SlideShare a Scribd company logo
1 of 74
GROUP: 2
WEEK:10
Vaniza 1922110048
Nimra shabbir 1922110028
Nayyab mir 1922110025
Sidra tahir 1922110043
Rukayia naz 1922110032
Tiamool tosha 1922110046
GROUP MEMBERS:
DECISION MAKING
LOOPING IN C#
Looping in C#
A loop repeats the same code several times. They make
calculations and processing elements in a collection
possible.
Types:
1.The for loop, which counts from one value to another.
2.The foreach loop, that easily iterates over all
elements in a collection.
3.The while loop, which goes on as long as some
condition is true.
4. The do-while loop, which always executes at least
once.
For Loop
▪ using System; Output:
0
▪ namespace MyApplication 1
2
▪ { 3
▪ class Program 4
▪ {
static void Main(string[] args)
▪ {
for (int i = 0; i < 5; i++)
▪ {
▪ Console.WriteLine(i); } }}}
Output:
0
using System; 1
namespace MyApplication 2
{ 3
class Program 4
{
static void Main(string[] args)
{
int i = 0;
while (i < 5)
{
Console.WriteLine(i);
i++;}}}}
While Loop
The Do/While Loop
▪ using System; Output 0
▪ namespace MyApplication 1
▪ { 2
▪ class Program 3
▪ {static void Main(string[] args)
▪ {
▪ int i = 0;
▪ do
▪ {
▪ Console.WriteLine(i);
▪ i++; }
▪ while (i < 4);}}}}
The foreach Loop
▪ using System; Output: Toyota
namespace MyApplication BMW
▪ { Suzuki
▪ class Program Mazda
▪ {
▪ static void Main(string[] args)
▪ {
▪ string[] cars = {“Toyota", "BMW", “Suzuki", "Mazda"};
▪ foreach (string i in cars)
▪ {
▪ Console.WriteLine(i);
▪ } }}}
BASIC CONCEPTS OF OOP
Basic concepts of OOPS
▪ Objects
▪ Classes
▪ Abstraction
▪ Encapsulation
▪ inheritence
Object oriented program
▪ In oop,problem is divided into the number of grouos called objects
and then builds data and functions around these objects.
▪ It ties the data more closely to the functions that operate on it,and
protects it from accidental modifications from the outside functions.
▪ Communication of the objects done through function.
OBJECTS
▪ An object in OOPS is nothing but a self-contained
component which consists of methods and properties to make a
particular type of data useful.
▪ For example color name, table, bag, barking.When you send a
message to an object, you are asking the object to invoke or execute
one of its methods as defined in the class
Object…….
▪ When a program is executed, the objects interact by sending
messages to one another.
▪ For e.g if customer and account are two objects in a program , then
the customer objects may send a message to the account object
requesting for the bank balance.
▪ Each object contains data, and code to manipulate the data.
classes
▪ Classes are user‐defined data types and it behaves like built in types
of programming language.
▪ • Object contains code and data which can be made user define
type using class.
▪ • Objects are variables of class.
Inheritance
▪ Using inheritance you can create a general class that defines traits
common to a set of related items.
▪ This class can then be inherited by other, more specific classes, each
adding those things that are unique to it. In the language of C#, a
class that is inherited is called a base class.
IMPLEMENTATION OF OOP OBJECTS IN
C#:
▪ Using system;
▪ Namespace oops
▪ {
▪ Class customer
▪ }
▪ // Member variables
▪ Public intcust ID;
▪ Public string name;
▪ Public string address;
// Constructor for initializing fields
Customer ()
{
CustID = 1101;
Name = “ time”;
Address = “ USA”;
}
// Method for displaying customer records ( functionality )
Public void display data()
{
Console.write line(“ customer =”+cust Id );
Console.write line (“ name= “+ name);
Console.write line(“ address=”+address);
}
//Code for entry point
}
}
Program:1
Output:
Customer id = 1101
Name = hello
Address = USA
Program:2
▪ Using system
▪ Namespace oops
▪ {
▪ Class program
▪ {
▪ Public void main function ()
▪ {
▪ Console.write line(“ main class”);
▪ }
▪ Static void main (string []args)
▪ {
▪ // Main class instance
▪ Program obj = new
Obj .main function ();
// Other class instance Program obj= new program ()
Obj . Main function ()
Other class instance
Demo d obj= new demo();
D obj.addition();
}
Class demo
{
Intx=10;
Int y=20;
Int z;
Public void addition
Z=x+y
Console.write line (“ other class is name space”);
Console.write line(z);
}
}
}
Output :
Main class
Other class is namespace
30
DATA TYPES IN C#
Data Types in C#:-
▪ A data type specifies the size and type of variable values.
▪ It means we must declare the type of a variable that indicates the
kind of values it is going to store, such as integer, float, decimal,
text, etc.
Data Types in C#:-
DataType Size Description
int 4 bytes Stores whole numbers from -2,147,483,648 to
2,147,483,647
long 8 bytes Stores whole numbers from -9,223,372,036,854,775,808.
float 4 bytes Stores fractional numbers. Sufficient for storing 6 to 7
decimal digits
double 8 bytes Stores fractional numbers. Sufficient for storing 15 decimal
digits
bool 1 bit Stores true or false values
char 2 bytes Stores a single character/letter, surrounded by single
quotes
string 2 bytes per
character
Stores a sequence of characters, surrounded by double
quotes
C# Classes and Objects:-
▪ Everything in C# is associated with classes and objects, along with its
attributes and methods. For example: in real life, a car is an object.The car
has attributes, such as weight and color, and methods, such as drive and
brake.
▪ A Class is like an object constructor, or a "blueprint" for creating objects.
▪ Create a Class
▪ To create a class, use the class keyword:
▪ Create a class named "Car" with a variable color:
▪ class Car
▪ {
▪ string color = "red";
▪ }
Code:-
▪ float floatVar = 10.2f;
▪ char charVar = 'A';
▪ bool boolVar = true;
▪ Console.WriteLine(stringVar);
▪ Console.WriteLine(intVar);
▪ Console.WriteLine(floatVar);
▪ Console.WriteLine(charVar);
▪ Console.WriteLine(boolVar);
▪ }
▪ }
Output:-
HelloWorld!!
100
10.2
A
True
▪ using System;
▪ public class Program
▪ {
▪ public static void Main() {
▪ string stringVar =
"HelloWorld!!";
▪ int intVar = 100;
Objects:-
▪ An object is created from a class. We have already created the class named Car, so now we can use this to
create objects.
▪ To create an object of Car, specify the class name, followed by the object name, and use the keyword new:
▪ using System;
▪ namespace MyApplication
▪ { output : red
▪ class Car
▪ {
▪ string color = "red";
▪ }
▪ sssCar myObj = new Car();
▪ Console.WriteLine(myObj.color);
▪ }
ARRAY AND SEARCHING IN
C#
ARRAY
Accessing array with for loop
Accessing Array using foreach Loop
LINQ Methods
How to search an element in array?
METHODS OF SEARCHING ELEMENTS IN ARRAY
▪ Linear search method
▪ Array.Find() method
▪ Array.FindAll() method
▪ Array.Findlast() mehod
LINEAR SEARCH METHOD
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main()
{
int i = 0 ;
int item = 0 ;
int pos = 0 ;
int[] arr = new int[5]; //Read numbers into array
Console.WriteLine("Enter elements : ");
for (i = 0; i < arr.Length; i++) {
Console.Write("Element[" + (i + 1) + "]: ");
arr[i] = int.Parse(Console.ReadLine());
}
Console.Write("Enter item to search : ");
item = int.Parse(Console.ReadLine()); //Loop to search element in array.
for (i = 0; i < arr.Length; i++) {
if (item == arr[i]) {
pos = i + 1;
break; } }
if (pos == 0) {
Console.WriteLine("Item Not found in array");
}
else
{
Console.WriteLine("Position of item in array: "+pos); } } } }
output
Output
Enter elements :
Element[1]: 25
Element[2]: 12
Element[3]: 13
Element[4]: 16
Element[5]: 29
Enter item to search :
16
Position of item in
array: 4
“
The Array.Find() method searches for an element that
matches the specified conditions using predicate
delegate, and returns the first occurrence within the
entire Array.”
Syntax:
public static T Find<T>(T[] array, Predicate<T> match);
Array.Find()
string[] names = {"Steve", "Bill", "Bill Gates", "Ravi",
"Mohan", "Salman", "Boski" };
var stringToFind = "Bill";
var result = Array.Find(names, element => element ==
stringToFind);
output// returns "Bill" - 3
Find literal value
string[] names = { "Steve", "Bill", "Bill Gates",
"James", "Mohan", "Salman", "Boski" };
var result = Array.Find(names, element =>
element.StartsWith("B"));
output// returns Bill
Find elements that starts with B
string[] names = { "Steve", "Bill", "James", "Mohan",
"Salman", "Boski" };
var result = Array.Find(names, element =>
element.Length >= 5);
output// returns Steve
Find by length
“The Array.FindAll() method returns all elements that match
the specified condition.”
Syntax:
public static T[]
FindAll<T>(T[] array, Predicate<T> match)
Array.FindAll()
string[] names = { "Steve", "Bill", "bill", "James",
"Mohan", "Salman", "Boski" };
var stringToFind = "bill";
string[] result = Array.FindAll(names, element =>
element.ToLower() == stringToFind);
output// return Bill, bill
Find literal values
string[] names = { "Steve", "Bill", "James", "Mohan",
"Salman", "Boski" };
string[] result = Array.FindAll(names, element =>
element.StartsWith("B"));
output// return Bill, Boski
Find all elements starting with B
string[] names = { "Steve", "Bill", "James", "Mohan",
"Salman", "Boski" };
string[] result = Array.FindAll(names, element =>
element.Length >= 5);
output// returns Steve, James, Mohan, Salman, Boski
Find elements by length
“The Array.Find() method returns the first element
that matches the condition.
The Array.FindLast() method returns the last element
that matches the specified condition in an array.”
Syntax:
public static T FindLast<T>(T[] array, Predicate<T>
match)
Array.FindLast()
string[] names = { "Steve", "Bill", "Bill Gates", "Ravi",
"Mohan", "Salman", "Boski" };
var stringToFind = "Bill";
var result = Array.FindLast(names, element =>
element.Contains(stringToFind));
output // returns "Boski"
Find last element
ThankYou

More Related Content

Similar to c#(loops,arrays)

The Ring programming language version 1.5.1 book - Part 36 of 180
The Ring programming language version 1.5.1 book - Part 36 of 180The Ring programming language version 1.5.1 book - Part 36 of 180
The Ring programming language version 1.5.1 book - Part 36 of 180Mahmoud Samir Fayed
 
[OOP - Lec 13,14,15] Constructors / Destructor and its Types
[OOP - Lec 13,14,15] Constructors / Destructor and its Types[OOP - Lec 13,14,15] Constructors / Destructor and its Types
[OOP - Lec 13,14,15] Constructors / Destructor and its TypesMuhammad Hammad Waseem
 
Constructors and Destructors
Constructors and DestructorsConstructors and Destructors
Constructors and DestructorsKeyur Vadodariya
 
Presentation 1st
Presentation 1stPresentation 1st
Presentation 1stConnex
 
JavaScript in 2016 (Codemotion Rome)
JavaScript in 2016 (Codemotion Rome)JavaScript in 2016 (Codemotion Rome)
JavaScript in 2016 (Codemotion Rome)Eduard Tomàs
 
JavaScript in 2016
JavaScript in 2016JavaScript in 2016
JavaScript in 2016Codemotion
 
Python-for-Data-Analysis.pdf
Python-for-Data-Analysis.pdfPython-for-Data-Analysis.pdf
Python-for-Data-Analysis.pdfssuser598883
 
React Native One Day
React Native One DayReact Native One Day
React Native One DayTroy Miles
 
The Ring programming language version 1.6 book - Part 40 of 189
The Ring programming language version 1.6 book - Part 40 of 189The Ring programming language version 1.6 book - Part 40 of 189
The Ring programming language version 1.6 book - Part 40 of 189Mahmoud Samir Fayed
 
The Ring programming language version 1.6 book - Part 32 of 189
The Ring programming language version 1.6 book - Part 32 of 189The Ring programming language version 1.6 book - Part 32 of 189
The Ring programming language version 1.6 book - Part 32 of 189Mahmoud Samir Fayed
 

Similar to c#(loops,arrays) (20)

The Ring programming language version 1.5.1 book - Part 36 of 180
The Ring programming language version 1.5.1 book - Part 36 of 180The Ring programming language version 1.5.1 book - Part 36 of 180
The Ring programming language version 1.5.1 book - Part 36 of 180
 
[OOP - Lec 13,14,15] Constructors / Destructor and its Types
[OOP - Lec 13,14,15] Constructors / Destructor and its Types[OOP - Lec 13,14,15] Constructors / Destructor and its Types
[OOP - Lec 13,14,15] Constructors / Destructor and its Types
 
Core java - baabtra
Core java - baabtraCore java - baabtra
Core java - baabtra
 
iOS Session-2
iOS Session-2iOS Session-2
iOS Session-2
 
Constructors and Destructors
Constructors and DestructorsConstructors and Destructors
Constructors and Destructors
 
Lecture 4. mte 407
Lecture 4. mte 407Lecture 4. mte 407
Lecture 4. mte 407
 
Oops lecture 1
Oops lecture 1Oops lecture 1
Oops lecture 1
 
Class and object C++.pptx
Class and object C++.pptxClass and object C++.pptx
Class and object C++.pptx
 
Presentation 1st
Presentation 1stPresentation 1st
Presentation 1st
 
Java Lab Manual
Java Lab ManualJava Lab Manual
Java Lab Manual
 
Spsl vi unit final
Spsl vi unit finalSpsl vi unit final
Spsl vi unit final
 
Spsl v unit - final
Spsl v unit - finalSpsl v unit - final
Spsl v unit - final
 
JavaScript in 2016 (Codemotion Rome)
JavaScript in 2016 (Codemotion Rome)JavaScript in 2016 (Codemotion Rome)
JavaScript in 2016 (Codemotion Rome)
 
JavaScript in 2016
JavaScript in 2016JavaScript in 2016
JavaScript in 2016
 
Python-for-Data-Analysis.pdf
Python-for-Data-Analysis.pdfPython-for-Data-Analysis.pdf
Python-for-Data-Analysis.pdf
 
React Native One Day
React Native One DayReact Native One Day
React Native One Day
 
Oops
OopsOops
Oops
 
The Ring programming language version 1.6 book - Part 40 of 189
The Ring programming language version 1.6 book - Part 40 of 189The Ring programming language version 1.6 book - Part 40 of 189
The Ring programming language version 1.6 book - Part 40 of 189
 
Synapseindia dot net development
Synapseindia dot net developmentSynapseindia dot net development
Synapseindia dot net development
 
The Ring programming language version 1.6 book - Part 32 of 189
The Ring programming language version 1.6 book - Part 32 of 189The Ring programming language version 1.6 book - Part 32 of 189
The Ring programming language version 1.6 book - Part 32 of 189
 

More from sdrhr

VIRUSES.pptx
VIRUSES.pptxVIRUSES.pptx
VIRUSES.pptxsdrhr
 
probability reasoning
probability reasoningprobability reasoning
probability reasoningsdrhr
 
GSM channels wireless
GSM channels  wirelessGSM channels  wireless
GSM channels wirelesssdrhr
 
database backup and recovery
database backup and recoverydatabase backup and recovery
database backup and recoverysdrhr
 
Social
SocialSocial
Socialsdrhr
 
social service
 social service social service
social servicesdrhr
 
Group8 ppt
Group8 pptGroup8 ppt
Group8 pptsdrhr
 
Agrobactrium mediated transformation
Agrobactrium mediated transformationAgrobactrium mediated transformation
Agrobactrium mediated transformationsdrhr
 
GENE MUTATION
       GENE  MUTATION       GENE  MUTATION
GENE MUTATIONsdrhr
 
Virtual function
Virtual functionVirtual function
Virtual functionsdrhr
 
Defects
DefectsDefects
Defectssdrhr
 
computer ethics
computer ethicscomputer ethics
computer ethicssdrhr
 

More from sdrhr (12)

VIRUSES.pptx
VIRUSES.pptxVIRUSES.pptx
VIRUSES.pptx
 
probability reasoning
probability reasoningprobability reasoning
probability reasoning
 
GSM channels wireless
GSM channels  wirelessGSM channels  wireless
GSM channels wireless
 
database backup and recovery
database backup and recoverydatabase backup and recovery
database backup and recovery
 
Social
SocialSocial
Social
 
social service
 social service social service
social service
 
Group8 ppt
Group8 pptGroup8 ppt
Group8 ppt
 
Agrobactrium mediated transformation
Agrobactrium mediated transformationAgrobactrium mediated transformation
Agrobactrium mediated transformation
 
GENE MUTATION
       GENE  MUTATION       GENE  MUTATION
GENE MUTATION
 
Virtual function
Virtual functionVirtual function
Virtual function
 
Defects
DefectsDefects
Defects
 
computer ethics
computer ethicscomputer ethics
computer ethics
 

Recently uploaded

Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 

Recently uploaded (20)

Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 

c#(loops,arrays)

  • 1.
  • 2. GROUP: 2 WEEK:10 Vaniza 1922110048 Nimra shabbir 1922110028 Nayyab mir 1922110025 Sidra tahir 1922110043 Rukayia naz 1922110032 Tiamool tosha 1922110046 GROUP MEMBERS:
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 14. Looping in C# A loop repeats the same code several times. They make calculations and processing elements in a collection possible. Types: 1.The for loop, which counts from one value to another. 2.The foreach loop, that easily iterates over all elements in a collection. 3.The while loop, which goes on as long as some condition is true. 4. The do-while loop, which always executes at least once.
  • 15. For Loop ▪ using System; Output: 0 ▪ namespace MyApplication 1 2 ▪ { 3 ▪ class Program 4 ▪ { static void Main(string[] args) ▪ { for (int i = 0; i < 5; i++) ▪ { ▪ Console.WriteLine(i); } }}}
  • 16. Output: 0 using System; 1 namespace MyApplication 2 { 3 class Program 4 { static void Main(string[] args) { int i = 0; while (i < 5) { Console.WriteLine(i); i++;}}}} While Loop
  • 17. The Do/While Loop ▪ using System; Output 0 ▪ namespace MyApplication 1 ▪ { 2 ▪ class Program 3 ▪ {static void Main(string[] args) ▪ { ▪ int i = 0; ▪ do ▪ { ▪ Console.WriteLine(i); ▪ i++; } ▪ while (i < 4);}}}}
  • 18. The foreach Loop ▪ using System; Output: Toyota namespace MyApplication BMW ▪ { Suzuki ▪ class Program Mazda ▪ { ▪ static void Main(string[] args) ▪ { ▪ string[] cars = {“Toyota", "BMW", “Suzuki", "Mazda"}; ▪ foreach (string i in cars) ▪ { ▪ Console.WriteLine(i); ▪ } }}}
  • 20. Basic concepts of OOPS ▪ Objects ▪ Classes ▪ Abstraction ▪ Encapsulation ▪ inheritence
  • 21. Object oriented program ▪ In oop,problem is divided into the number of grouos called objects and then builds data and functions around these objects. ▪ It ties the data more closely to the functions that operate on it,and protects it from accidental modifications from the outside functions. ▪ Communication of the objects done through function.
  • 22. OBJECTS ▪ An object in OOPS is nothing but a self-contained component which consists of methods and properties to make a particular type of data useful. ▪ For example color name, table, bag, barking.When you send a message to an object, you are asking the object to invoke or execute one of its methods as defined in the class
  • 23.
  • 24.
  • 25. Object……. ▪ When a program is executed, the objects interact by sending messages to one another. ▪ For e.g if customer and account are two objects in a program , then the customer objects may send a message to the account object requesting for the bank balance. ▪ Each object contains data, and code to manipulate the data.
  • 26. classes ▪ Classes are user‐defined data types and it behaves like built in types of programming language. ▪ • Object contains code and data which can be made user define type using class. ▪ • Objects are variables of class.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35. Inheritance ▪ Using inheritance you can create a general class that defines traits common to a set of related items. ▪ This class can then be inherited by other, more specific classes, each adding those things that are unique to it. In the language of C#, a class that is inherited is called a base class.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41. IMPLEMENTATION OF OOP OBJECTS IN C#:
  • 42. ▪ Using system; ▪ Namespace oops ▪ { ▪ Class customer ▪ } ▪ // Member variables ▪ Public intcust ID; ▪ Public string name; ▪ Public string address; // Constructor for initializing fields Customer () { CustID = 1101; Name = “ time”; Address = “ USA”; } // Method for displaying customer records ( functionality ) Public void display data() { Console.write line(“ customer =”+cust Id ); Console.write line (“ name= “+ name); Console.write line(“ address=”+address); } //Code for entry point } } Program:1
  • 43. Output: Customer id = 1101 Name = hello Address = USA
  • 45. ▪ Using system ▪ Namespace oops ▪ { ▪ Class program ▪ { ▪ Public void main function () ▪ { ▪ Console.write line(“ main class”); ▪ } ▪ Static void main (string []args) ▪ { ▪ // Main class instance ▪ Program obj = new Obj .main function (); // Other class instance Program obj= new program () Obj . Main function () Other class instance Demo d obj= new demo(); D obj.addition(); } Class demo { Intx=10; Int y=20; Int z; Public void addition Z=x+y Console.write line (“ other class is name space”); Console.write line(z); } } }
  • 46. Output : Main class Other class is namespace 30
  • 48. Data Types in C#:- ▪ A data type specifies the size and type of variable values. ▪ It means we must declare the type of a variable that indicates the kind of values it is going to store, such as integer, float, decimal, text, etc.
  • 49. Data Types in C#:- DataType Size Description int 4 bytes Stores whole numbers from -2,147,483,648 to 2,147,483,647 long 8 bytes Stores whole numbers from -9,223,372,036,854,775,808. float 4 bytes Stores fractional numbers. Sufficient for storing 6 to 7 decimal digits double 8 bytes Stores fractional numbers. Sufficient for storing 15 decimal digits bool 1 bit Stores true or false values char 2 bytes Stores a single character/letter, surrounded by single quotes string 2 bytes per character Stores a sequence of characters, surrounded by double quotes
  • 50. C# Classes and Objects:- ▪ Everything in C# is associated with classes and objects, along with its attributes and methods. For example: in real life, a car is an object.The car has attributes, such as weight and color, and methods, such as drive and brake. ▪ A Class is like an object constructor, or a "blueprint" for creating objects. ▪ Create a Class ▪ To create a class, use the class keyword: ▪ Create a class named "Car" with a variable color: ▪ class Car ▪ { ▪ string color = "red"; ▪ }
  • 51. Code:- ▪ float floatVar = 10.2f; ▪ char charVar = 'A'; ▪ bool boolVar = true; ▪ Console.WriteLine(stringVar); ▪ Console.WriteLine(intVar); ▪ Console.WriteLine(floatVar); ▪ Console.WriteLine(charVar); ▪ Console.WriteLine(boolVar); ▪ } ▪ } Output:- HelloWorld!! 100 10.2 A True ▪ using System; ▪ public class Program ▪ { ▪ public static void Main() { ▪ string stringVar = "HelloWorld!!"; ▪ int intVar = 100;
  • 52. Objects:- ▪ An object is created from a class. We have already created the class named Car, so now we can use this to create objects. ▪ To create an object of Car, specify the class name, followed by the object name, and use the keyword new: ▪ using System; ▪ namespace MyApplication ▪ { output : red ▪ class Car ▪ { ▪ string color = "red"; ▪ } ▪ sssCar myObj = new Car(); ▪ Console.WriteLine(myObj.color); ▪ }
  • 54. ARRAY
  • 56. Accessing Array using foreach Loop
  • 58. How to search an element in array?
  • 59. METHODS OF SEARCHING ELEMENTS IN ARRAY ▪ Linear search method ▪ Array.Find() method ▪ Array.FindAll() method ▪ Array.Findlast() mehod
  • 61. using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication1 { class Program { static void Main() { int i = 0 ; int item = 0 ; int pos = 0 ; int[] arr = new int[5]; //Read numbers into array Console.WriteLine("Enter elements : "); for (i = 0; i < arr.Length; i++) { Console.Write("Element[" + (i + 1) + "]: "); arr[i] = int.Parse(Console.ReadLine()); }
  • 62. Console.Write("Enter item to search : "); item = int.Parse(Console.ReadLine()); //Loop to search element in array. for (i = 0; i < arr.Length; i++) { if (item == arr[i]) { pos = i + 1; break; } } if (pos == 0) { Console.WriteLine("Item Not found in array"); } else { Console.WriteLine("Position of item in array: "+pos); } } } }
  • 63. output Output Enter elements : Element[1]: 25 Element[2]: 12 Element[3]: 13 Element[4]: 16 Element[5]: 29 Enter item to search : 16 Position of item in array: 4
  • 64. “ The Array.Find() method searches for an element that matches the specified conditions using predicate delegate, and returns the first occurrence within the entire Array.” Syntax: public static T Find<T>(T[] array, Predicate<T> match); Array.Find()
  • 65. string[] names = {"Steve", "Bill", "Bill Gates", "Ravi", "Mohan", "Salman", "Boski" }; var stringToFind = "Bill"; var result = Array.Find(names, element => element == stringToFind); output// returns "Bill" - 3 Find literal value
  • 66. string[] names = { "Steve", "Bill", "Bill Gates", "James", "Mohan", "Salman", "Boski" }; var result = Array.Find(names, element => element.StartsWith("B")); output// returns Bill Find elements that starts with B
  • 67. string[] names = { "Steve", "Bill", "James", "Mohan", "Salman", "Boski" }; var result = Array.Find(names, element => element.Length >= 5); output// returns Steve Find by length
  • 68. “The Array.FindAll() method returns all elements that match the specified condition.” Syntax: public static T[] FindAll<T>(T[] array, Predicate<T> match) Array.FindAll()
  • 69. string[] names = { "Steve", "Bill", "bill", "James", "Mohan", "Salman", "Boski" }; var stringToFind = "bill"; string[] result = Array.FindAll(names, element => element.ToLower() == stringToFind); output// return Bill, bill Find literal values
  • 70. string[] names = { "Steve", "Bill", "James", "Mohan", "Salman", "Boski" }; string[] result = Array.FindAll(names, element => element.StartsWith("B")); output// return Bill, Boski Find all elements starting with B
  • 71. string[] names = { "Steve", "Bill", "James", "Mohan", "Salman", "Boski" }; string[] result = Array.FindAll(names, element => element.Length >= 5); output// returns Steve, James, Mohan, Salman, Boski Find elements by length
  • 72. “The Array.Find() method returns the first element that matches the condition. The Array.FindLast() method returns the last element that matches the specified condition in an array.” Syntax: public static T FindLast<T>(T[] array, Predicate<T> match) Array.FindLast()
  • 73. string[] names = { "Steve", "Bill", "Bill Gates", "Ravi", "Mohan", "Salman", "Boski" }; var stringToFind = "Bill"; var result = Array.FindLast(names, element => element.Contains(stringToFind)); output // returns "Boski" Find last element