SlideShare a Scribd company logo
Arrays
❑ Simple arrays
❑ Multidimensional arrays
❑ Jagged arrays
Arrays
• If you need to work with multiple objects of
the same type, you can arrays.
• Simple Arrays
– If you need to use multiple objects of the same
type, you can use an array. An array is a data
structure that contains a number of elements of
the same type.
Array Declaration & Array Initialization
• The array cannot be resized after the size was
specified without copying all elements.
int[] myArray;
myArray = new int[4];
Using an array initializer
int[] myArray = new int[4] {4, 7, 11, 2};
int[] myArray = new int[] {4, 7, 11, 2};
int[] myArray = {4, 7, 11, 2};
Accessing Array Elements
• After an array is declared and initialized, you can access
the array elements using an indexer. Arrays only
support indexers that have integer parameters.
– int[] myArray = new int[] {4, 7, 11, 2};
– int v1 = myArray[0]; // read first element
– int v2 = myArray[1]; // read second element
– myArray[3] = 44; // change fourth element
• If you use a wrong indexer value where no element
exists, an exception of type
IndexOutOfRangeException is thrown.
• If you don ’ t know the number of elements in
the array, you can use the Length property
for (int i = 0; i < myArray.Length; i++)
{
Console.WriteLine(myArray[i]);
}
Rajpat Systems
Multidimensional Arrays
• You cannot change the rank after declaring an array.
– int[,] twodim = new int[3, 3];
– twodim[0, 0] = 1;
– twodim[0, 1] = 2;
– twodim[0, 2] = 3;
– twodim[1, 0] = 4;
– twodim[1, 1] = 5;
– twodim[1, 2] = 6;
– twodim[2, 0] = 7;
– twodim[2, 1] = 8;
– twodim[2, 2] = 9;
Using an array initializer
• When using an array initializer, you must
initialize every element of the array. It is not
possible to leave the initialization for some
values.
Jagged Arrays
• A jagged array is more flexible in sizing the array.
• With a jagged array every row can have a different
size.
int[][] jagged = new int[3][];
jagged[0] = new int[2] { 1, 2 };
jagged[1] = new int[6] { 3, 4, 5, 6, 7, 8 };
jagged[2] = new int[3] { 9, 10, 11 };
for (int row = 0; row < jagged.Length; row++)
{
for (int element = 0; element < jagged[row].Length; element++)
{
Console.WriteLine(“row: {0}, element: {1}, value: {2}”,
row, element, jagged[row][element]
);
}
}
foreach Statement
• The C# foreach statement is not resolved to a foreach statement in
the IL code. Instead, the C# compiler converts the foreach
statement to methods and properties of the IEnumerable interface.

More Related Content

What's hot

An Introduction to Programming in Java: Arrays
An Introduction to Programming in Java: ArraysAn Introduction to Programming in Java: Arrays
An Introduction to Programming in Java: Arrays
Martin Chapman
 
Array in Java
Array in JavaArray in Java
Array in Java
Shehrevar Davierwala
 
Java arrays
Java arraysJava arrays
Java arrays
BHUVIJAYAVELU
 
Java Arrays
Java ArraysJava Arrays
Java Arrays
Jussi Pohjolainen
 
Module 7 : Arrays
Module 7 : ArraysModule 7 : Arrays
Module 7 : Arrays
Prem Kumar Badri
 
Arrays in java
Arrays in javaArrays in java
Arrays in java
TharuniDiddekunta
 
Arrays Class presentation
Arrays Class presentationArrays Class presentation
Arrays Class presentation
Neveen Reda
 
Lec 25 - arrays-strings
Lec 25 - arrays-stringsLec 25 - arrays-strings
Lec 25 - arrays-strings
Princess Sam
 
intorduction to Arrays in java
intorduction to Arrays in javaintorduction to Arrays in java
intorduction to Arrays in java
Muthukumaran Subramanian
 
Arrays
ArraysArrays
Java Arrays
Java ArraysJava Arrays
Java Arrays
OXUS 20
 
Arrays in Java
Arrays in JavaArrays in Java
Arrays in Java
Abhilash Nair
 
Class notes(week 4) on arrays and strings
Class notes(week 4) on arrays and stringsClass notes(week 4) on arrays and strings
Class notes(week 4) on arrays and strings
Kuntal Bhowmick
 
C# Arrays
C# ArraysC# Arrays
C# Arrays
Hock Leng PUAH
 
Array lecture
Array lectureArray lecture
Array lecture
Joan Saño
 
7array in c#
7array in c#7array in c#
7array in c#
Sireesh K
 
2 dimension array in programms
2 dimension array in programms2 dimension array in programms
2 dimension array in programms
Anil Pokhrel
 
12. arrays
12. arrays12. arrays
Arrays in java language
Arrays in java languageArrays in java language
Arrays in java language
Hareem Naz
 
Learn Java Part 8
Learn Java Part 8Learn Java Part 8
Learn Java Part 8
Gurpreet singh
 

What's hot (20)

An Introduction to Programming in Java: Arrays
An Introduction to Programming in Java: ArraysAn Introduction to Programming in Java: Arrays
An Introduction to Programming in Java: Arrays
 
Array in Java
Array in JavaArray in Java
Array in Java
 
Java arrays
Java arraysJava arrays
Java arrays
 
Java Arrays
Java ArraysJava Arrays
Java Arrays
 
Module 7 : Arrays
Module 7 : ArraysModule 7 : Arrays
Module 7 : Arrays
 
Arrays in java
Arrays in javaArrays in java
Arrays in java
 
Arrays Class presentation
Arrays Class presentationArrays Class presentation
Arrays Class presentation
 
Lec 25 - arrays-strings
Lec 25 - arrays-stringsLec 25 - arrays-strings
Lec 25 - arrays-strings
 
intorduction to Arrays in java
intorduction to Arrays in javaintorduction to Arrays in java
intorduction to Arrays in java
 
Arrays
ArraysArrays
Arrays
 
Java Arrays
Java ArraysJava Arrays
Java Arrays
 
Arrays in Java
Arrays in JavaArrays in Java
Arrays in Java
 
Class notes(week 4) on arrays and strings
Class notes(week 4) on arrays and stringsClass notes(week 4) on arrays and strings
Class notes(week 4) on arrays and strings
 
C# Arrays
C# ArraysC# Arrays
C# Arrays
 
Array lecture
Array lectureArray lecture
Array lecture
 
7array in c#
7array in c#7array in c#
7array in c#
 
2 dimension array in programms
2 dimension array in programms2 dimension array in programms
2 dimension array in programms
 
12. arrays
12. arrays12. arrays
12. arrays
 
Arrays in java language
Arrays in java languageArrays in java language
Arrays in java language
 
Learn Java Part 8
Learn Java Part 8Learn Java Part 8
Learn Java Part 8
 

Similar to C# Lesson 3

arrays in c# including Classes handling arrays
arrays in c#  including Classes handling arraysarrays in c#  including Classes handling arrays
arrays in c# including Classes handling arrays
JayanthiM19
 
Array
ArrayArray
Array
PRN USM
 
javaarray
javaarrayjavaarray
javaarray
Arjun Shanka
 
Python array
Python arrayPython array
Python array
Arnab Chakraborty
 
Arrays
ArraysArrays
Mesics lecture 8 arrays in 'c'
Mesics lecture 8   arrays in 'c'Mesics lecture 8   arrays in 'c'
Mesics lecture 8 arrays in 'c'
eShikshak
 
L10 array
L10 arrayL10 array
L10 array
teach4uin
 
C++ Arrays
C++ ArraysC++ Arrays
C++ Arrays
أحمد محمد
 
C++ Arrays
C++ ArraysC++ Arrays
C++ Arrays
أحمد محمد
 
6 arrays injava
6 arrays injava6 arrays injava
6 arrays injava
irdginfo
 
M251_Meeting 2_updated_2.pdf(M251_Meeting 2_updated_2.pdf)
M251_Meeting 2_updated_2.pdf(M251_Meeting 2_updated_2.pdf)M251_Meeting 2_updated_2.pdf(M251_Meeting 2_updated_2.pdf)
M251_Meeting 2_updated_2.pdf(M251_Meeting 2_updated_2.pdf)
hossamghareb681
 
Arrays in java (signle dimensional array)
Arrays in java (signle dimensional array)Arrays in java (signle dimensional array)
Arrays in java (signle dimensional array)
Talha mahmood
 
Generative Coding Lecture notes using coding
Generative Coding Lecture notes using codingGenerative Coding Lecture notes using coding
Generative Coding Lecture notes using coding
ssuserff773c
 
Lecture 4
Lecture 4Lecture 4
Lecture 4
Skillspire LLC
 
Basic Arrays in C Programming Language I
Basic Arrays in C Programming Language IBasic Arrays in C Programming Language I
Basic Arrays in C Programming Language I
ChobodiDamsaraniPadm
 
Chap 6 c++
Chap 6 c++Chap 6 c++
Array-part1
Array-part1Array-part1
Array-part1
AbishaiAsir
 
Class notes(week 4) on arrays and strings
Class notes(week 4) on arrays and stringsClass notes(week 4) on arrays and strings
Class notes(week 4) on arrays and strings
Kuntal Bhowmick
 
Array
ArrayArray
javaArrays.pptx
javaArrays.pptxjavaArrays.pptx
javaArrays.pptx
AshishNayyar11
 

Similar to C# Lesson 3 (20)

arrays in c# including Classes handling arrays
arrays in c#  including Classes handling arraysarrays in c#  including Classes handling arrays
arrays in c# including Classes handling arrays
 
Array
ArrayArray
Array
 
javaarray
javaarrayjavaarray
javaarray
 
Python array
Python arrayPython array
Python array
 
Arrays
ArraysArrays
Arrays
 
Mesics lecture 8 arrays in 'c'
Mesics lecture 8   arrays in 'c'Mesics lecture 8   arrays in 'c'
Mesics lecture 8 arrays in 'c'
 
L10 array
L10 arrayL10 array
L10 array
 
C++ Arrays
C++ ArraysC++ Arrays
C++ Arrays
 
C++ Arrays
C++ ArraysC++ Arrays
C++ Arrays
 
6 arrays injava
6 arrays injava6 arrays injava
6 arrays injava
 
M251_Meeting 2_updated_2.pdf(M251_Meeting 2_updated_2.pdf)
M251_Meeting 2_updated_2.pdf(M251_Meeting 2_updated_2.pdf)M251_Meeting 2_updated_2.pdf(M251_Meeting 2_updated_2.pdf)
M251_Meeting 2_updated_2.pdf(M251_Meeting 2_updated_2.pdf)
 
Arrays in java (signle dimensional array)
Arrays in java (signle dimensional array)Arrays in java (signle dimensional array)
Arrays in java (signle dimensional array)
 
Generative Coding Lecture notes using coding
Generative Coding Lecture notes using codingGenerative Coding Lecture notes using coding
Generative Coding Lecture notes using coding
 
Lecture 4
Lecture 4Lecture 4
Lecture 4
 
Basic Arrays in C Programming Language I
Basic Arrays in C Programming Language IBasic Arrays in C Programming Language I
Basic Arrays in C Programming Language I
 
Chap 6 c++
Chap 6 c++Chap 6 c++
Chap 6 c++
 
Array-part1
Array-part1Array-part1
Array-part1
 
Class notes(week 4) on arrays and strings
Class notes(week 4) on arrays and stringsClass notes(week 4) on arrays and strings
Class notes(week 4) on arrays and strings
 
Array
ArrayArray
Array
 
javaArrays.pptx
javaArrays.pptxjavaArrays.pptx
javaArrays.pptx
 

More from Bohdan Pashkovskyi

Telegram bots
Telegram botsTelegram bots
Telegram bots
Bohdan Pashkovskyi
 
CoreCamp "Automated testing basics for developers"
CoreCamp "Automated testing basics for developers"CoreCamp "Automated testing basics for developers"
CoreCamp "Automated testing basics for developers"
Bohdan Pashkovskyi
 
CQRS and Event Sourcing
CQRS and Event SourcingCQRS and Event Sourcing
CQRS and Event Sourcing
Bohdan Pashkovskyi
 
C# Lesson 1
C# Lesson 1C# Lesson 1
C# Lesson 1
Bohdan Pashkovskyi
 
Automated testing
Automated testingAutomated testing
Automated testing
Bohdan Pashkovskyi
 
IF .NET User Group
IF .NET User GroupIF .NET User Group
IF .NET User Group
Bohdan Pashkovskyi
 
Asynchronous programming in C#
Asynchronous programming in C#Asynchronous programming in C#
Asynchronous programming in C#
Bohdan Pashkovskyi
 
ASP .NET MVC - best practices
ASP .NET MVC - best practicesASP .NET MVC - best practices
ASP .NET MVC - best practices
Bohdan Pashkovskyi
 
.Net Core
.Net Core.Net Core

More from Bohdan Pashkovskyi (9)

Telegram bots
Telegram botsTelegram bots
Telegram bots
 
CoreCamp "Automated testing basics for developers"
CoreCamp "Automated testing basics for developers"CoreCamp "Automated testing basics for developers"
CoreCamp "Automated testing basics for developers"
 
CQRS and Event Sourcing
CQRS and Event SourcingCQRS and Event Sourcing
CQRS and Event Sourcing
 
C# Lesson 1
C# Lesson 1C# Lesson 1
C# Lesson 1
 
Automated testing
Automated testingAutomated testing
Automated testing
 
IF .NET User Group
IF .NET User GroupIF .NET User Group
IF .NET User Group
 
Asynchronous programming in C#
Asynchronous programming in C#Asynchronous programming in C#
Asynchronous programming in C#
 
ASP .NET MVC - best practices
ASP .NET MVC - best practicesASP .NET MVC - best practices
ASP .NET MVC - best practices
 
.Net Core
.Net Core.Net Core
.Net Core
 

Recently uploaded

The Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collectionThe Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collection
Israel Genealogy Research Association
 
writing about opinions about Australia the movie
writing about opinions about Australia the moviewriting about opinions about Australia the movie
writing about opinions about Australia the movie
Nicholas Montgomery
 
clinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdfclinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdf
Priyankaranawat4
 
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
RitikBhardwaj56
 
Main Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docxMain Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docx
adhitya5119
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
heathfieldcps1
 
Hindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdfHindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdf
Dr. Mulla Adam Ali
 
Film vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movieFilm vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movie
Nicholas Montgomery
 
PIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf IslamabadPIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf Islamabad
AyyanKhan40
 
World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024
ak6969907
 
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective UpskillingYour Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Excellence Foundation for South Sudan
 
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Dr. Vinod Kumar Kanvaria
 
South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)
Academy of Science of South Africa
 
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama UniversityNatural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Akanksha trivedi rama nursing college kanpur.
 
PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.
Dr. Shivangi Singh Parihar
 
Digital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments UnitDigital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments Unit
chanes7
 
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdfANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
Priyankaranawat4
 
MARY JANE WILSON, A “BOA MÃE” .
MARY JANE WILSON, A “BOA MÃE”           .MARY JANE WILSON, A “BOA MÃE”           .
MARY JANE WILSON, A “BOA MÃE” .
Colégio Santa Teresinha
 
Assessment and Planning in Educational technology.pptx
Assessment and Planning in Educational technology.pptxAssessment and Planning in Educational technology.pptx
Assessment and Planning in Educational technology.pptx
Kavitha Krishnan
 
Liberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdfLiberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdf
WaniBasim
 

Recently uploaded (20)

The Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collectionThe Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collection
 
writing about opinions about Australia the movie
writing about opinions about Australia the moviewriting about opinions about Australia the movie
writing about opinions about Australia the movie
 
clinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdfclinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdf
 
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
 
Main Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docxMain Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docx
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
 
Hindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdfHindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdf
 
Film vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movieFilm vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movie
 
PIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf IslamabadPIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf Islamabad
 
World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024
 
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective UpskillingYour Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective Upskilling
 
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
 
South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)
 
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama UniversityNatural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
 
PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.
 
Digital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments UnitDigital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments Unit
 
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdfANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
 
MARY JANE WILSON, A “BOA MÃE” .
MARY JANE WILSON, A “BOA MÃE”           .MARY JANE WILSON, A “BOA MÃE”           .
MARY JANE WILSON, A “BOA MÃE” .
 
Assessment and Planning in Educational technology.pptx
Assessment and Planning in Educational technology.pptxAssessment and Planning in Educational technology.pptx
Assessment and Planning in Educational technology.pptx
 
Liberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdfLiberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdf
 

C# Lesson 3

  • 1. Arrays ❑ Simple arrays ❑ Multidimensional arrays ❑ Jagged arrays
  • 2. Arrays • If you need to work with multiple objects of the same type, you can arrays. • Simple Arrays – If you need to use multiple objects of the same type, you can use an array. An array is a data structure that contains a number of elements of the same type.
  • 3. Array Declaration & Array Initialization • The array cannot be resized after the size was specified without copying all elements. int[] myArray; myArray = new int[4]; Using an array initializer int[] myArray = new int[4] {4, 7, 11, 2}; int[] myArray = new int[] {4, 7, 11, 2}; int[] myArray = {4, 7, 11, 2};
  • 4. Accessing Array Elements • After an array is declared and initialized, you can access the array elements using an indexer. Arrays only support indexers that have integer parameters. – int[] myArray = new int[] {4, 7, 11, 2}; – int v1 = myArray[0]; // read first element – int v2 = myArray[1]; // read second element – myArray[3] = 44; // change fourth element • If you use a wrong indexer value where no element exists, an exception of type IndexOutOfRangeException is thrown.
  • 5. • If you don ’ t know the number of elements in the array, you can use the Length property for (int i = 0; i < myArray.Length; i++) { Console.WriteLine(myArray[i]); } Rajpat Systems
  • 6. Multidimensional Arrays • You cannot change the rank after declaring an array. – int[,] twodim = new int[3, 3]; – twodim[0, 0] = 1; – twodim[0, 1] = 2; – twodim[0, 2] = 3; – twodim[1, 0] = 4; – twodim[1, 1] = 5; – twodim[1, 2] = 6; – twodim[2, 0] = 7; – twodim[2, 1] = 8; – twodim[2, 2] = 9;
  • 7. Using an array initializer • When using an array initializer, you must initialize every element of the array. It is not possible to leave the initialization for some values.
  • 8.
  • 9. Jagged Arrays • A jagged array is more flexible in sizing the array. • With a jagged array every row can have a different size. int[][] jagged = new int[3][]; jagged[0] = new int[2] { 1, 2 }; jagged[1] = new int[6] { 3, 4, 5, 6, 7, 8 }; jagged[2] = new int[3] { 9, 10, 11 };
  • 10. for (int row = 0; row < jagged.Length; row++) { for (int element = 0; element < jagged[row].Length; element++) { Console.WriteLine(“row: {0}, element: {1}, value: {2}”, row, element, jagged[row][element] ); } }
  • 11. foreach Statement • The C# foreach statement is not resolved to a foreach statement in the IL code. Instead, the C# compiler converts the foreach statement to methods and properties of the IEnumerable interface.