SlideShare a Scribd company logo
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

More Related Content

What's hot (20)

PPTX
Flow Control (C#)
Bhushan Mulmule
 
PPTX
Windows form application_in_vb(vb.net --3 year)
Ankit Gupta
 
PPTX
C++ string
Dheenadayalan18
 
PPTX
Python-Inheritance.pptx
Karudaiyar Ganapathy
 
PPTX
DHCP & DNS
NetProtocol Xpert
 
PPTX
Classes and objects
rajveer_Pannu
 
PPT
C by balaguruswami - e.balagurusamy
Srichandan Sobhanayak
 
PPTX
Looping Statements and Control Statements in Python
PriyankaC44
 
PPTX
Subnetting Presentation
Touhidul Fahim
 
PPTX
2CPP14 - Abstraction
Michael Heron
 
PPTX
The Loops
Krishma Parekh
 
ODP
OOP java
xball977
 
PPTX
C if else
Ritwik Das
 
PPTX
Inline functions
DhwaniHingorani
 
PDF
Structures in c++
Swarup Kumar Boro
 
PPTX
Sdi & mdi
BABAVALI S
 
PPTX
Decision making and branching in c programming
Priyansh Thakar
 
PDF
Files and streams
Pranali Chaudhari
 
Flow Control (C#)
Bhushan Mulmule
 
Windows form application_in_vb(vb.net --3 year)
Ankit Gupta
 
C++ string
Dheenadayalan18
 
Python-Inheritance.pptx
Karudaiyar Ganapathy
 
DHCP & DNS
NetProtocol Xpert
 
Classes and objects
rajveer_Pannu
 
C by balaguruswami - e.balagurusamy
Srichandan Sobhanayak
 
Looping Statements and Control Statements in Python
PriyankaC44
 
Subnetting Presentation
Touhidul Fahim
 
2CPP14 - Abstraction
Michael Heron
 
The Loops
Krishma Parekh
 
OOP java
xball977
 
C if else
Ritwik Das
 
Inline functions
DhwaniHingorani
 
Structures in c++
Swarup Kumar Boro
 
Sdi & mdi
BABAVALI S
 
Decision making and branching in c programming
Priyansh Thakar
 
Files and streams
Pranali Chaudhari
 

Viewers also liked (16)

PDF
Windows Forms For Beginners Part 5
Bhushan Mulmule
 
PDF
NInject - DI Container
Bhushan Mulmule
 
PPT
scanf function in c, variations in conversion specifier
herosaikiran
 
PDF
Dependency injection for beginners
Bhushan Mulmule
 
PDF
Implementing auto complete using JQuery
Bhushan Mulmule
 
PPTX
Concept of c data types
Manisha Keim
 
PDF
1.3 data types
Digitorious Technologies
 
PDF
Windows Forms For Beginners Part - 4
Bhushan Mulmule
 
PDF
Windows Forms For Beginners Part - 2
Bhushan Mulmule
 
PPTX
C data types, arrays and structs
Saad Sheikh
 
PDF
Windows Forms For Beginners Part - 3
Bhushan Mulmule
 
PDF
Windows Forms For Beginners Part - 1
Bhushan Mulmule
 
PPTX
Introduction to Array ppt
sandhya yadav
 
PPT
Computer Programming- Lecture 5
Dr. Md. Shohel Sayeed
 
PPT
Chap3 flow charts
amit139
 
PPTX
Operator in c programming
Manoj Tyagi
 
Windows Forms For Beginners Part 5
Bhushan Mulmule
 
NInject - DI Container
Bhushan Mulmule
 
scanf function in c, variations in conversion specifier
herosaikiran
 
Dependency injection for beginners
Bhushan Mulmule
 
Implementing auto complete using JQuery
Bhushan Mulmule
 
Concept of c data types
Manisha Keim
 
1.3 data types
Digitorious Technologies
 
Windows Forms For Beginners Part - 4
Bhushan Mulmule
 
Windows Forms For Beginners Part - 2
Bhushan Mulmule
 
C data types, arrays and structs
Saad Sheikh
 
Windows Forms For Beginners Part - 3
Bhushan Mulmule
 
Windows Forms For Beginners Part - 1
Bhushan Mulmule
 
Introduction to Array ppt
sandhya yadav
 
Computer Programming- Lecture 5
Dr. Md. Shohel Sayeed
 
Chap3 flow charts
amit139
 
Operator in c programming
Manoj Tyagi
 
Ad

Similar to Arrays, Structures And Enums (20)

DOCX
.net progrmming part2
Dr.M.Karthika parthasarathy
 
PPTX
20.1 Java working with abstraction
Intro C# Book
 
RTF
CBSE Grade12, Computer Science, Sample Question Paper
Malathi Senthil
 
PPTX
OOP-Lecture-05 (Constructor_Destructor).pptx
SirRafiLectures
 
PPT
Basic c#
kishore4268
 
PPS
Wrapper class
kamal kotecha
 
PPTX
Unit 3
GOWSIKRAJAP
 
PPTX
4Developers 2018: Ile (nie) wiesz o strukturach w .NET (Łukasz Pyrzyk)
PROIDEA
 
PDF
Intake 38 3
Mahmoud Ouf
 
PPTX
Generics in .NET, C++ and Java
Sasha Goldshtein
 
PPTX
Week_02_Lec_ Java Intro continueed..pptx
ibrahemtariq
 
PPT
Attributes & .NET components
Bình Trọng Án
 
PPT
TechTalk - Dotnet
heinrich.wendel
 
PPTX
Tools and Techniques for Understanding Threading Behavior in Android*
Intel® Software
 
PPT
Arrays in c programing. practicals and .ppt
Carlos701746
 
PDF
Programming Fundamentals Arrays and Strings
imtiazalijoono
 
PDF
ádfasdfasdfasdfasdfasdfsadfsadfasdfasfasdfasdfasdfa
Vu Dang
 
PDF
22 scheme OOPs with C++ BCS306B_module2.pdfmodule2.pdf
sindhus795217
 
PPTX
Java fundamentals
HCMUTE
 
.net progrmming part2
Dr.M.Karthika parthasarathy
 
20.1 Java working with abstraction
Intro C# Book
 
CBSE Grade12, Computer Science, Sample Question Paper
Malathi Senthil
 
OOP-Lecture-05 (Constructor_Destructor).pptx
SirRafiLectures
 
Basic c#
kishore4268
 
Wrapper class
kamal kotecha
 
Unit 3
GOWSIKRAJAP
 
4Developers 2018: Ile (nie) wiesz o strukturach w .NET (Łukasz Pyrzyk)
PROIDEA
 
Intake 38 3
Mahmoud Ouf
 
Generics in .NET, C++ and Java
Sasha Goldshtein
 
Week_02_Lec_ Java Intro continueed..pptx
ibrahemtariq
 
Attributes & .NET components
Bình Trọng Án
 
TechTalk - Dotnet
heinrich.wendel
 
Tools and Techniques for Understanding Threading Behavior in Android*
Intel® Software
 
Arrays in c programing. practicals and .ppt
Carlos701746
 
Programming Fundamentals Arrays and Strings
imtiazalijoono
 
ádfasdfasdfasdfasdfasdfsadfsadfasdfasfasdfasdfasdfa
Vu Dang
 
22 scheme OOPs with C++ BCS306B_module2.pdfmodule2.pdf
sindhus795217
 
Java fundamentals
HCMUTE
 
Ad

More from Bhushan Mulmule (6)

PPTX
Understanding Interfaces
Bhushan Mulmule
 
PPTX
Polymorphism
Bhushan Mulmule
 
PPTX
Inheritance
Bhushan Mulmule
 
PPTX
Methods
Bhushan Mulmule
 
PPTX
Getting started with C# Programming
Bhushan Mulmule
 
PPTX
Overview of .Net Framework 4.5
Bhushan Mulmule
 
Understanding Interfaces
Bhushan Mulmule
 
Polymorphism
Bhushan Mulmule
 
Inheritance
Bhushan Mulmule
 
Getting started with C# Programming
Bhushan Mulmule
 
Overview of .Net Framework 4.5
Bhushan Mulmule
 

Recently uploaded (20)

PPTX
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
PDF
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
PDF
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
PDF
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
PDF
Fl Studio 24.2.2 Build 4597 Crack for Windows Free Download 2025
faizk77g
 
PDF
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
PDF
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
PDF
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
PDF
DevBcn - Building 10x Organizations Using Modern Productivity Metrics
Justin Reock
 
PPTX
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
PDF
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
PDF
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
PDF
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
PDF
HCIP-Data Center Facility Deployment V2.0 Training Material (Without Remarks ...
mcastillo49
 
PDF
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
PDF
July Patch Tuesday
Ivanti
 
PDF
What Makes Contify’s News API Stand Out: Key Features at a Glance
Contify
 
PPTX
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
PDF
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
PPTX
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
Fl Studio 24.2.2 Build 4597 Crack for Windows Free Download 2025
faizk77g
 
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
DevBcn - Building 10x Organizations Using Modern Productivity Metrics
Justin Reock
 
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
HCIP-Data Center Facility Deployment V2.0 Training Material (Without Remarks ...
mcastillo49
 
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
July Patch Tuesday
Ivanti
 
What Makes Contify’s News API Stand Out: Key Features at a Glance
Contify
 
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 

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