SlideShare une entreprise Scribd logo
1  sur  20
Bhushan Mulmule
bhushan.mulmule@dotnetvideotutorial.com
www.dotnetvideotutorial.com
For video visit
www.dotnetvideotutorial.com
Agenda
 Single Dimensional Array
 Array Class
 Array of Reference Type
 Double Dimensional Array
 Jagged Array
 Structure
 Enum
www.dotnetvideotutorial.com
Array
 Data structure holding multiple values of same data-type
 Are reference type
 Derived from abstract base class Array
20 50 60
0 1 2
Arrays are zero
indexed
Last index is always
(size – 1)
5000
5000
marks
www.dotnetvideotutorial.com
Array Declarations
// Declare a single-dimensional array
int[] array1 = new int[5];
// Declare and set array element values, Size can be skipped
int[] array2 = new int[] { 1, 3, 5, 7, 9 };
// Alternative syntax. new keyword can be skipped
int[] array3 = { 1, 3, 5, 7, 9 };
// Declaration and instantiation on separate lines
int[] array4;
array4 = new int[5];
5000
5000
array1
0 1 2 3 4
www.dotnetvideotutorial.com
0 0 0
int[] marks = new int[3];
Console.WriteLine("Enter marks in three subjects:");
for (int i = 0; i < 3; i++)
marks[i] = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Marks obtained:");
Console.WriteLine("Printed using for loop");
for (int i = 0; i < 3; i++)
Console.WriteLine(marks[i]);
Console.WriteLine("Printed using foreach loop");
foreach (int m in marks)
{
Console.WriteLine(m);
}
20 50 60
5000
5000
marks
The default value for elements
of numeric array is zero
0 1 2
Single Dimensional Array
www.dotnetvideotutorial.com
Array Class
 Base class for all arrays in the common language runtime.
 Provides methods for creating, manipulating, searching, and
sorting arrays
www.dotnetvideotutorial.com
Array Class
int[] numbers = { 78, 54, 76, 23, 87 };
//sorting
Array.Sort(numbers);
Console.WriteLine("sorted array: ");
for (int i = 0; i < numbers.Length; i++)
Console.WriteLine(numbers[i]);
//reversing
Array.Reverse(numbers);
...
//finding out index
int index = Array.IndexOf(numbers, 54);
Console.WriteLine("Index of 54: " + index);
www.dotnetvideotutorial.com
Array of Reference Types
static void Main(string[] args)
{
string[] computers = { "Titan", "Mira", "K computer" };
Console.WriteLine("Fastest Super Computers: n");
foreach (string n in computers)
{
Console.WriteLine(n);
}
}
2000 2200 1800
Titan
Mira
K Computer
2000 1800
2200
5000
5000
Computers
Note: Default value for elements
of reference array is null
int[,] marks = new int[3, 4];
for (int i = 0; i < 3; i++)
{
C.WL("Enter marks in 4 subjects of Student {0}", i + 1);
for (int j = 0; j < 4; j++)
{
marks[i, j] = Convert.ToInt32(Console.ReadLine());
}
}
0 0 0 0
0 0 0 0
0 0 0 0
40 50 60 70
80 90 70 80
30 50 80 70
0
1
2
0 1 2 3
2D Array
www.dotnetvideotutorial.com
Console.WriteLine("---------------Score Board------------------");
for (int i = 0; i < 3; i++)
{
Console.Write("Student {0}:tt", i + 1);
for (int j = 0; j < 4; j++)
{
Console.Write(marks[i, j] + "t");
}
Console.WriteLine();
} 0 0 0 0
0 0 0 0
0 0 0 0
40 50 60 70
80 90 70 80
30 50 80 70
0
1
2
0 1 2 3
2D Array
www.dotnetvideotutorial.com
Jagged Array
 Array of Arrays: A jagged array is an array whose elements are
arrays.
 The elements of a jagged array can be of different dimensions
and sizes.
 Syntax:
type[][] identifier = new type[size][];
www.dotnetvideotutorial.com
Jagged Array
int[][] a = new int[3][];
a[0] = new int[2] { 32, 54 };
a[1] = new int[4] { 78, 96, 46, 38 };
a[2] = new int[3] { 54, 76, 23 };
2000
1800
2200
5000
5000
a
2000 2200 1800
32 54 54 76 23
78 96 46 38
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < a[i].Length; j++)
{
Console.Write(a[i][j] + "t");
}
Console.WriteLine();
}
2000
1800
2200
5000
5000
a
2000 2200 1800
32 54 54 76 23
78 96 46 38
Struct
 Keyword to create user defined datatype
 Typically used to encapsulate small groups of related variables
 A struct type is a value type
 Structs can implement an interface but can't inherit from
another struct or class.
NOTE: structs can contain constructors, constants, fields, methods, properties,
indexers, operators, events, and nested types, although if several such members are
required, consider making your type a class instead.
struct Point
{
public int x;
public int y;
}
class Program
{
static void Main(string[] args)
{
Point p1;
Console.WriteLine("Enter X and Y axis of point:");
p1.x = Convert.ToInt32(Console.ReadLine());
p1.y = Convert.ToInt32(Console.ReadLine());
C.WL("Coordinates of p1: x = {0}, y = {1}", p1.x, p1.y);
Console.ReadKey();
}
}
0 0
p1
x y
10 20
www.dotnetvideotutorial.com
Enum
enum Gender
{
Male,
Female,
Other
}
Gender g1 = Gender.Female;
1
g1
www.dotnetvideotutorial.com
Enums
 The enum keyword is used to declare an enumeration, a distinct
type consisting of a set of named constants called the
enumerator list.
 The default underlying type of the enumeration elements is int.
 By default, the first enumerator has the value 0, and the value of
each successive enumerator is increased by 1.
www.dotnetvideotutorial.com
enum Gender
{
Male = 10,
Female,
Other
}
class Program
{
static void Main(string[] args)
{
Gender g1 = Gender.Female;
C.WL("g1 represents {0}. But value stored is {1}", g1, (int)g1);
Gender g2 = Gender.Male;
C.WL("g2 represents {0}. But value stored is {1}", g2, (int)g2);
}
}
11
10
g1
g2
www.dotnetvideotutorial.com
Bhushan Mulmule
bhushan.mulmule@dotnetvideotutorial.com
www.dotnetvideotutorial.com

Contenu connexe

Tendances (20)

Oops concept on c#
Oops concept on c#Oops concept on c#
Oops concept on c#
 
ArrayList in JAVA
ArrayList in JAVAArrayList in JAVA
ArrayList in JAVA
 
Java Swing
Java SwingJava Swing
Java Swing
 
Properties and indexers in C#
Properties and indexers in C#Properties and indexers in C#
Properties and indexers in C#
 
7.data types in c#
7.data types in c#7.data types in c#
7.data types in c#
 
C# Access modifiers
C# Access modifiersC# Access modifiers
C# Access modifiers
 
Inner classes in java
Inner classes in javaInner classes in java
Inner classes in java
 
Literals,variables,datatype in C#
Literals,variables,datatype in C#Literals,variables,datatype in C#
Literals,variables,datatype in C#
 
Inheritance in c++
Inheritance in c++Inheritance in c++
Inheritance in c++
 
Control flow statements in java
Control flow statements in javaControl flow statements in java
Control flow statements in java
 
This keyword in java
This keyword in javaThis keyword in java
This keyword in java
 
Loops in c++ programming language
Loops in c++ programming language Loops in c++ programming language
Loops in c++ programming language
 
Control Statements in Java
Control Statements in JavaControl Statements in Java
Control Statements in Java
 
Java awt
Java awtJava awt
Java awt
 
Friend functions
Friend functions Friend functions
Friend functions
 
Java(Polymorphism)
Java(Polymorphism)Java(Polymorphism)
Java(Polymorphism)
 
Super keyword in java
Super keyword in javaSuper keyword in java
Super keyword in java
 
10. funtions and closures IN SWIFT PROGRAMMING
10. funtions and closures IN SWIFT PROGRAMMING10. funtions and closures IN SWIFT PROGRAMMING
10. funtions and closures IN SWIFT PROGRAMMING
 
Data Types & Variables in JAVA
Data Types & Variables in JAVAData Types & Variables in JAVA
Data Types & Variables in JAVA
 
Awt controls ppt
Awt controls pptAwt controls ppt
Awt controls ppt
 

En vedette

Windows Forms For Beginners Part 5
Windows Forms For Beginners Part 5Windows Forms For Beginners Part 5
Windows Forms For Beginners Part 5Bhushan Mulmule
 
scanf function in c, variations in conversion specifier
scanf function in c, variations in conversion specifierscanf function in c, variations in conversion specifier
scanf function in c, variations in conversion specifierherosaikiran
 
Dependency injection for beginners
Dependency injection for beginnersDependency injection for beginners
Dependency injection for beginnersBhushan Mulmule
 
Implementing auto complete using JQuery
Implementing auto complete using JQueryImplementing auto complete using JQuery
Implementing auto complete using JQueryBhushan Mulmule
 
Concept of c data types
Concept of c data typesConcept of c data types
Concept of c data typesManisha Keim
 
Windows Forms For Beginners Part - 4
Windows Forms For Beginners Part - 4Windows Forms For Beginners Part - 4
Windows Forms For Beginners Part - 4Bhushan Mulmule
 
Windows Forms For Beginners Part - 2
Windows Forms For Beginners Part - 2Windows Forms For Beginners Part - 2
Windows Forms For Beginners Part - 2Bhushan Mulmule
 
C data types, arrays and structs
C data types, arrays and structsC data types, arrays and structs
C data types, arrays and structsSaad Sheikh
 
Windows Forms For Beginners Part - 3
Windows Forms For Beginners Part - 3Windows Forms For Beginners Part - 3
Windows Forms For Beginners Part - 3Bhushan Mulmule
 
Windows Forms For Beginners Part - 1
Windows Forms For Beginners Part - 1Windows Forms For Beginners Part - 1
Windows Forms For Beginners Part - 1Bhushan Mulmule
 
Introduction to Array ppt
Introduction to Array pptIntroduction to Array ppt
Introduction to Array pptsandhya yadav
 
Chap3 flow charts
Chap3 flow chartsChap3 flow charts
Chap3 flow chartsamit139
 
Operator in c programming
Operator in c programmingOperator in c programming
Operator in c programmingManoj Tyagi
 

En vedette (16)

Windows Forms For Beginners Part 5
Windows Forms For Beginners Part 5Windows Forms For Beginners Part 5
Windows Forms For Beginners Part 5
 
NInject - DI Container
NInject - DI ContainerNInject - DI Container
NInject - DI Container
 
scanf function in c, variations in conversion specifier
scanf function in c, variations in conversion specifierscanf function in c, variations in conversion specifier
scanf function in c, variations in conversion specifier
 
Dependency injection for beginners
Dependency injection for beginnersDependency injection for beginners
Dependency injection for beginners
 
Implementing auto complete using JQuery
Implementing auto complete using JQueryImplementing auto complete using JQuery
Implementing auto complete using JQuery
 
Concept of c data types
Concept of c data typesConcept of c data types
Concept of c data types
 
1.3 data types
1.3 data types1.3 data types
1.3 data types
 
Windows Forms For Beginners Part - 4
Windows Forms For Beginners Part - 4Windows Forms For Beginners Part - 4
Windows Forms For Beginners Part - 4
 
Windows Forms For Beginners Part - 2
Windows Forms For Beginners Part - 2Windows Forms For Beginners Part - 2
Windows Forms For Beginners Part - 2
 
C data types, arrays and structs
C data types, arrays and structsC data types, arrays and structs
C data types, arrays and structs
 
Windows Forms For Beginners Part - 3
Windows Forms For Beginners Part - 3Windows Forms For Beginners Part - 3
Windows Forms For Beginners Part - 3
 
Windows Forms For Beginners Part - 1
Windows Forms For Beginners Part - 1Windows Forms For Beginners Part - 1
Windows Forms For Beginners Part - 1
 
Introduction to Array ppt
Introduction to Array pptIntroduction to Array ppt
Introduction to Array ppt
 
Computer Programming- Lecture 5
Computer Programming- Lecture 5 Computer Programming- Lecture 5
Computer Programming- Lecture 5
 
Chap3 flow charts
Chap3 flow chartsChap3 flow charts
Chap3 flow charts
 
Operator in c programming
Operator in c programmingOperator in c programming
Operator in c programming
 

Similaire à Arrays, Structures And Enums

20.1 Java working with abstraction
20.1 Java working with abstraction20.1 Java working with abstraction
20.1 Java working with abstractionIntro C# Book
 
CBSE Grade12, Computer Science, Sample Question Paper
CBSE Grade12, Computer Science, Sample Question PaperCBSE Grade12, Computer Science, Sample Question Paper
CBSE Grade12, Computer Science, Sample Question PaperMalathi Senthil
 
OOP-Lecture-05 (Constructor_Destructor).pptx
OOP-Lecture-05 (Constructor_Destructor).pptxOOP-Lecture-05 (Constructor_Destructor).pptx
OOP-Lecture-05 (Constructor_Destructor).pptxSirRafiLectures
 
4Developers 2018: Ile (nie) wiesz o strukturach w .NET (Łukasz Pyrzyk)
4Developers 2018: Ile (nie) wiesz o strukturach w .NET (Łukasz Pyrzyk)4Developers 2018: Ile (nie) wiesz o strukturach w .NET (Łukasz Pyrzyk)
4Developers 2018: Ile (nie) wiesz o strukturach w .NET (Łukasz Pyrzyk)PROIDEA
 
Generics in .NET, C++ and Java
Generics in .NET, C++ and JavaGenerics in .NET, C++ and Java
Generics in .NET, C++ and JavaSasha Goldshtein
 
Attributes & .NET components
Attributes & .NET componentsAttributes & .NET components
Attributes & .NET componentsBình Trọng Án
 
Tools and Techniques for Understanding Threading Behavior in Android*
Tools and Techniques for Understanding Threading Behavior in Android*Tools and Techniques for Understanding Threading Behavior in Android*
Tools and Techniques for Understanding Threading Behavior in Android*Intel® Software
 
Programming Fundamentals Arrays and Strings
Programming Fundamentals   Arrays and Strings Programming Fundamentals   Arrays and Strings
Programming Fundamentals Arrays and Strings imtiazalijoono
 
Java fundamentals
Java fundamentalsJava fundamentals
Java fundamentalsHCMUTE
 
Arrays and function basic c programming notes
Arrays and function basic c programming notesArrays and function basic c programming notes
Arrays and function basic c programming notesGOKULKANNANMMECLECTC
 

Similaire à Arrays, Structures And Enums (20)

ASP.NET
ASP.NETASP.NET
ASP.NET
 
.net progrmming part2
.net progrmming part2.net progrmming part2
.net progrmming part2
 
20.1 Java working with abstraction
20.1 Java working with abstraction20.1 Java working with abstraction
20.1 Java working with abstraction
 
CBSE Grade12, Computer Science, Sample Question Paper
CBSE Grade12, Computer Science, Sample Question PaperCBSE Grade12, Computer Science, Sample Question Paper
CBSE Grade12, Computer Science, Sample Question Paper
 
OOP-Lecture-05 (Constructor_Destructor).pptx
OOP-Lecture-05 (Constructor_Destructor).pptxOOP-Lecture-05 (Constructor_Destructor).pptx
OOP-Lecture-05 (Constructor_Destructor).pptx
 
Basic c#
Basic c#Basic c#
Basic c#
 
Wrapper class
Wrapper classWrapper class
Wrapper class
 
Unit 3
Unit 3 Unit 3
Unit 3
 
4Developers 2018: Ile (nie) wiesz o strukturach w .NET (Łukasz Pyrzyk)
4Developers 2018: Ile (nie) wiesz o strukturach w .NET (Łukasz Pyrzyk)4Developers 2018: Ile (nie) wiesz o strukturach w .NET (Łukasz Pyrzyk)
4Developers 2018: Ile (nie) wiesz o strukturach w .NET (Łukasz Pyrzyk)
 
Intake 38 3
Intake 38 3Intake 38 3
Intake 38 3
 
Generics in .NET, C++ and Java
Generics in .NET, C++ and JavaGenerics in .NET, C++ and Java
Generics in .NET, C++ and Java
 
Attributes & .NET components
Attributes & .NET componentsAttributes & .NET components
Attributes & .NET components
 
TechTalk - Dotnet
TechTalk - DotnetTechTalk - Dotnet
TechTalk - Dotnet
 
Tools and Techniques for Understanding Threading Behavior in Android*
Tools and Techniques for Understanding Threading Behavior in Android*Tools and Techniques for Understanding Threading Behavior in Android*
Tools and Techniques for Understanding Threading Behavior in Android*
 
Programming Fundamentals Arrays and Strings
Programming Fundamentals   Arrays and Strings Programming Fundamentals   Arrays and Strings
Programming Fundamentals Arrays and Strings
 
C#2
C#2C#2
C#2
 
Java fundamentals
Java fundamentalsJava fundamentals
Java fundamentals
 
Doc 20180130-wa0006
Doc 20180130-wa0006Doc 20180130-wa0006
Doc 20180130-wa0006
 
Arrays and function basic c programming notes
Arrays and function basic c programming notesArrays and function basic c programming notes
Arrays and function basic c programming notes
 
CH1 ARRAY (1).pptx
CH1 ARRAY (1).pptxCH1 ARRAY (1).pptx
CH1 ARRAY (1).pptx
 

Plus de Bhushan Mulmule

Plus de Bhushan Mulmule (6)

Understanding Interfaces
Understanding InterfacesUnderstanding Interfaces
Understanding Interfaces
 
Polymorphism
PolymorphismPolymorphism
Polymorphism
 
Inheritance
InheritanceInheritance
Inheritance
 
Methods
MethodsMethods
Methods
 
Getting started with C# Programming
Getting started with C# ProgrammingGetting started with C# Programming
Getting started with C# Programming
 
Overview of .Net Framework 4.5
Overview of .Net Framework 4.5Overview of .Net Framework 4.5
Overview of .Net Framework 4.5
 

Dernier

ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdfChristopherTHyatt
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
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
 
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
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
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
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 

Dernier (20)

ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdf
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
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
 
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
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
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
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 

Arrays, Structures And Enums

  • 3. Agenda  Single Dimensional Array  Array Class  Array of Reference Type  Double Dimensional Array  Jagged Array  Structure  Enum www.dotnetvideotutorial.com
  • 4. Array  Data structure holding multiple values of same data-type  Are reference type  Derived from abstract base class Array 20 50 60 0 1 2 Arrays are zero indexed Last index is always (size – 1) 5000 5000 marks www.dotnetvideotutorial.com
  • 5. Array Declarations // Declare a single-dimensional array int[] array1 = new int[5]; // Declare and set array element values, Size can be skipped int[] array2 = new int[] { 1, 3, 5, 7, 9 }; // Alternative syntax. new keyword can be skipped int[] array3 = { 1, 3, 5, 7, 9 }; // Declaration and instantiation on separate lines int[] array4; array4 = new int[5]; 5000 5000 array1 0 1 2 3 4 www.dotnetvideotutorial.com
  • 6. 0 0 0 int[] marks = new int[3]; Console.WriteLine("Enter marks in three subjects:"); for (int i = 0; i < 3; i++) marks[i] = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("Marks obtained:"); Console.WriteLine("Printed using for loop"); for (int i = 0; i < 3; i++) Console.WriteLine(marks[i]); Console.WriteLine("Printed using foreach loop"); foreach (int m in marks) { Console.WriteLine(m); } 20 50 60 5000 5000 marks The default value for elements of numeric array is zero 0 1 2 Single Dimensional Array www.dotnetvideotutorial.com
  • 7. Array Class  Base class for all arrays in the common language runtime.  Provides methods for creating, manipulating, searching, and sorting arrays www.dotnetvideotutorial.com
  • 8. Array Class int[] numbers = { 78, 54, 76, 23, 87 }; //sorting Array.Sort(numbers); Console.WriteLine("sorted array: "); for (int i = 0; i < numbers.Length; i++) Console.WriteLine(numbers[i]); //reversing Array.Reverse(numbers); ... //finding out index int index = Array.IndexOf(numbers, 54); Console.WriteLine("Index of 54: " + index); www.dotnetvideotutorial.com
  • 9. Array of Reference Types static void Main(string[] args) { string[] computers = { "Titan", "Mira", "K computer" }; Console.WriteLine("Fastest Super Computers: n"); foreach (string n in computers) { Console.WriteLine(n); } } 2000 2200 1800 Titan Mira K Computer 2000 1800 2200 5000 5000 Computers Note: Default value for elements of reference array is null
  • 10. int[,] marks = new int[3, 4]; for (int i = 0; i < 3; i++) { C.WL("Enter marks in 4 subjects of Student {0}", i + 1); for (int j = 0; j < 4; j++) { marks[i, j] = Convert.ToInt32(Console.ReadLine()); } } 0 0 0 0 0 0 0 0 0 0 0 0 40 50 60 70 80 90 70 80 30 50 80 70 0 1 2 0 1 2 3 2D Array www.dotnetvideotutorial.com
  • 11. Console.WriteLine("---------------Score Board------------------"); for (int i = 0; i < 3; i++) { Console.Write("Student {0}:tt", i + 1); for (int j = 0; j < 4; j++) { Console.Write(marks[i, j] + "t"); } Console.WriteLine(); } 0 0 0 0 0 0 0 0 0 0 0 0 40 50 60 70 80 90 70 80 30 50 80 70 0 1 2 0 1 2 3 2D Array www.dotnetvideotutorial.com
  • 12. Jagged Array  Array of Arrays: A jagged array is an array whose elements are arrays.  The elements of a jagged array can be of different dimensions and sizes.  Syntax: type[][] identifier = new type[size][]; www.dotnetvideotutorial.com
  • 13. Jagged Array int[][] a = new int[3][]; a[0] = new int[2] { 32, 54 }; a[1] = new int[4] { 78, 96, 46, 38 }; a[2] = new int[3] { 54, 76, 23 }; 2000 1800 2200 5000 5000 a 2000 2200 1800 32 54 54 76 23 78 96 46 38
  • 14. for (int i = 0; i < 3; i++) { for (int j = 0; j < a[i].Length; j++) { Console.Write(a[i][j] + "t"); } Console.WriteLine(); } 2000 1800 2200 5000 5000 a 2000 2200 1800 32 54 54 76 23 78 96 46 38
  • 15. Struct  Keyword to create user defined datatype  Typically used to encapsulate small groups of related variables  A struct type is a value type  Structs can implement an interface but can't inherit from another struct or class. NOTE: structs can contain constructors, constants, fields, methods, properties, indexers, operators, events, and nested types, although if several such members are required, consider making your type a class instead.
  • 16. struct Point { public int x; public int y; } class Program { static void Main(string[] args) { Point p1; Console.WriteLine("Enter X and Y axis of point:"); p1.x = Convert.ToInt32(Console.ReadLine()); p1.y = Convert.ToInt32(Console.ReadLine()); C.WL("Coordinates of p1: x = {0}, y = {1}", p1.x, p1.y); Console.ReadKey(); } } 0 0 p1 x y 10 20 www.dotnetvideotutorial.com
  • 17. Enum enum Gender { Male, Female, Other } Gender g1 = Gender.Female; 1 g1 www.dotnetvideotutorial.com
  • 18. Enums  The enum keyword is used to declare an enumeration, a distinct type consisting of a set of named constants called the enumerator list.  The default underlying type of the enumeration elements is int.  By default, the first enumerator has the value 0, and the value of each successive enumerator is increased by 1. www.dotnetvideotutorial.com
  • 19. enum Gender { Male = 10, Female, Other } class Program { static void Main(string[] args) { Gender g1 = Gender.Female; C.WL("g1 represents {0}. But value stored is {1}", g1, (int)g1); Gender g2 = Gender.Male; C.WL("g2 represents {0}. But value stored is {1}", g2, (int)g2); } } 11 10 g1 g2 www.dotnetvideotutorial.com