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

Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Jeffrey Haguewood
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...apidays
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsNanddeep Nachan
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesrafiqahmad00786416
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...apidays
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfOrbitshub
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...Zilliz
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Victor Rentea
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024The Digital Insurer
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdfSandro Moreira
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 

Recently uploaded (20)

Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 

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