SlideShare uma empresa Scribd logo
1 de 42
Baixar para ler offline
Learn C# Programming
Nullables & Arrays
Eng Teong Cheah
Microsoft MVP in Visual Studio &
Development Technologies
Agenda
•Nullables
•Arrays
•Strings
•Structure
•Enums
C# - Nullables
C# - Nullables
C# provides a special data types, the nullable types, to which you can
assign normal range of values as well as null values.
For example, you can store any value from -2,147,483,648 to 2,
147,483, 647 or null in a Nullable<Int32> variable. Similarly, you can
assign true, false, or null in a Nullable<bool> variable. Syntax for
declaring a nullable type is as follows:
< data_type> ? <variable_name> = null;
Demo
C# - Nullables
The Null Coalescing Operator(??)
The null coalescing operator is used with the nullable value types and
reference types. It is used for converting an operand to the type of
another nullable (or not) value type operand, where an implicit
conversion is possible.
Demo
C# - Arrays
C# - Arrays
An array stores a fixed-size sequential collection of elements of the
same type. An array is used to store a collection of data, but it is
often more useful to think of an array as a collection of variables of
the same type stored at contiguous memory locations.
Instead of declaring individual variables, such as number0, number1,
…, and number99, you declare one array variable such as numbers
and use numbers[0], numbers[1], and …, numbers[99] to represent
individual variables. A specific element in an array is accessed by an
index.
C# - Arrays
All arrays consist of contiguous memory locations. The lowest
address corresponds to the first element and the highest address to
the last element.
C# - Arrays
Declaring Arrays
To declare an array in C#, you can use the following syntax:
where,
datatype[] arrayName;
C# - Arrays
where,
- datatype is used to specify the type of elements in the array.
- [ ] specifies the rank of the array. The rank specifies the size of the
array.
- arrayName specifies the name of the array.
For example,
double[] balance;
Declaring Arrays
C# - Arrays
Initializing Arrays
Declaring an array does not initialize the array in the memory. When
the array variable is initialized, you can assign values to the array.
Array is a reference type, so you need to use the new keyword to
create an instance of the array. For example,
double[] balance = new double[10];
C# - Arrays
Assigning Values to an Array
You can assign values to individual array elements, by using the index
number, like:
You can assign values to the array at the time of declaration, as
shown:
double[] balance = new double[10];
balance[0] = 4500.0;
double[] balance = { 2340.0, 4523.69, 3421.0};
C# - Arrays
You can also create and initialize an array, as shown:
You may also omit the size of the array, as shown:
int [] marks = new int[5] { 99, 98, 92, 97, 95};
int [] marks = new int[] { 99, 98, 92, 97, 95};
C# - Arrays
You can copy an array variable into another target array variable. In
such case, both the target and source point to the same memory
location:
When you create an array, C# compiler implicitly initializes each array
element to a default value depending on the array type. For example,
for an int array all elements are initialized to 0.
int [] marks = new int[] { 99, 98, 92, 97, 95};
int[] score = marks;
C# - Arrays
Accessing Array Elements
An element is accessed by indexing the array name. This is done by
placing the index of the element within square brackets after the
name of the array. For example,
double salary = balance[9];
Demo
C# - Arrays
Using the foreach Loop
In the previous example, we used a for loop for accessing each array
element. You can also use a foreach statement to iterate through an
array.
Demo
C# - Arrays
There are following few important concepts related to array which
should be clear to a C# programmer:
- Multi-dimensional arrays
- Jagged arrays
- Passing arrays to functions
- Param arrays
- The Array Class
C# - Arrays
Multidimensional Arrays
C# allows multidimensional arrays. Multi-dimensional arrays are also
called rectangular array. You can declare a 2-dimensional array of
strings as:
or, a 3-dimensional array of int variables as:
string [,] names;
int [ , , ] m;
C# - Arrays
Multidimensional Arrays
Two-Dimensional Arrays
The simplest form of the multidimensional array is the 2-dimensional
array. A 2-dimensional array is a list of one-dimensional arrays.
C# - Arrays
A 2-dimensional array can be thought of as a table, which has x
number of rows and y number of columns. Following is a 2-
dimensional array, which contains 3 rows and 4 columns.
C# - Arrays
Thus, every element in the array a is identified by an element name
of the form a[i,j], where a is the name of the array, and i and j are the
subscripts that uniquely identify each element in array a.
C# - Arrays
Initializing Two-Dimensional Arrays
Multidimensional arrays may be initialized by specifying bracketed
values for each row. The following array is with 3 rows and each row
has 4 columns.
int [,] a = new int [3,4] {
{0, 1, 2, 3} , /* initializers for row indexed by 0 */
{4, 5, 6, 7} , /* initializers for row indexed by 1 */
{8, 9, 10, 11} /* initializers for row indexed by 2 */
};
C# - Arrays
Accessing Two-Dimensional Array Elements
An element in 2-dimensional array is accessed by using the
subscripts. That is, row index and column index of the array. For
example,
The above statement takes 4th element form the 3rd row of the array.
You can verify it in the above diagram.
int val = a[2,3];
Demo
C# - Arrays
Jagged Arrays
A Jagged array is an arrays. You can declare a jagged array named
scores of type int as:
int [][] scores;
C# - Arrays
Jagged Arrays
Declaring an array, does not create the array in memory. To create
the above array:
int[][] scores = new int[5][];
for (int i = 0; i < scores.Length; i++)
{
scores[i] = new int[4];
}
C# - Arrays
Jagged Arrays
You can initialize a jagged array as:
Where, scores is an array of two arrays of integers – scores[0] is an
array of 3 integers and scores[1] is an array of 4 integers.
int[][] scores = new int[2][]{new int[]{92,93,94},new int[]{85,66,87,88}};
Demo
C# - Arrays
Passing Arrays as Function Arguments
You can pass an array as a function argument in C#.
Demo
C# - Arrays
Param Array
At times, while declaring a method, you are not sure of the number
of arguments passed as a parameter. C# param arrays (or parameter
arrays) come into help at such times.
Demo
C# - Arrays
Array Class
The Array class is the base class for all the arrays in C#. It is defined in
the System namespace. The Array class provides various properties
and methods to work with arrays.
C# - Arrays
Properties of the
Array Class
The following table
describes some of the
most commonly used
properties of the
Array class:
C# - Arrays
Methods of the Array
Class
The following table
describes some of the
most commonly used
methods of the Array
class:
C# - Arrays
Methods of the Array
Class
The following table
describes some of the
most commonly used
methods of the Array
class:
Related Content
•TutorialsPoint
www.tutorialspoint.com
Thank You

Mais conteúdo relacionado

Mais procurados

Structure of c_program_to_input_output
Structure of c_program_to_input_outputStructure of c_program_to_input_output
Structure of c_program_to_input_output
Anil Dutt
 
Basic of the C language
Basic of the C languageBasic of the C language
Basic of the C language
Sachin Verma
 
structure and union
structure and unionstructure and union
structure and union
student
 
Ch2 introduction to c
Ch2 introduction to cCh2 introduction to c
Ch2 introduction to c
Hattori Sidek
 

Mais procurados (20)

Variables in C Programming
Variables in C ProgrammingVariables in C Programming
Variables in C Programming
 
Structure of c_program_to_input_output
Structure of c_program_to_input_outputStructure of c_program_to_input_output
Structure of c_program_to_input_output
 
Constants in C Programming
Constants in C ProgrammingConstants in C Programming
Constants in C Programming
 
Learn C# Programming - Decision Making & Loops
Learn C# Programming - Decision Making & LoopsLearn C# Programming - Decision Making & Loops
Learn C# Programming - Decision Making & Loops
 
Variables in C and C++ Language
Variables in C and C++ LanguageVariables in C and C++ Language
Variables in C and C++ Language
 
What is identifier c programming
What is identifier c programmingWhat is identifier c programming
What is identifier c programming
 
Structure
StructureStructure
Structure
 
Assignment2
Assignment2Assignment2
Assignment2
 
Basic of the C language
Basic of the C languageBasic of the C language
Basic of the C language
 
C programming Training in Ambala ! Batra Computer Centre
C programming Training in Ambala ! Batra Computer CentreC programming Training in Ambala ! Batra Computer Centre
C programming Training in Ambala ! Batra Computer Centre
 
C tokens
C tokensC tokens
C tokens
 
Introduction to Basic C programming 01
Introduction to Basic C programming 01Introduction to Basic C programming 01
Introduction to Basic C programming 01
 
structure and union
structure and unionstructure and union
structure and union
 
C Language (All Concept)
C Language (All Concept)C Language (All Concept)
C Language (All Concept)
 
Clanguage
ClanguageClanguage
Clanguage
 
Unit 2. Elements of C
Unit 2. Elements of CUnit 2. Elements of C
Unit 2. Elements of C
 
Basic Structure Of C++
Basic Structure Of C++Basic Structure Of C++
Basic Structure Of C++
 
Ch2 introduction to c
Ch2 introduction to cCh2 introduction to c
Ch2 introduction to c
 
C# chap 4
C# chap 4C# chap 4
C# chap 4
 
Basics of C programming
Basics of C programmingBasics of C programming
Basics of C programming
 

Semelhante a Learn C# Programming - Nullables & Arrays

Arrays In General
Arrays In GeneralArrays In General
Arrays In General
martha leon
 
Homework Assignment – Array Technical DocumentWrite a technical .pdf
Homework Assignment – Array Technical DocumentWrite a technical .pdfHomework Assignment – Array Technical DocumentWrite a technical .pdf
Homework Assignment – Array Technical DocumentWrite a technical .pdf
aroraopticals15
 
C++ - UNIT_-_IV.pptx which contains details about Pointers
C++ - UNIT_-_IV.pptx which contains details about PointersC++ - UNIT_-_IV.pptx which contains details about Pointers
C++ - UNIT_-_IV.pptx which contains details about Pointers
ANUSUYA S
 

Semelhante a Learn C# Programming - Nullables & Arrays (20)

Arrays In General
Arrays In GeneralArrays In General
Arrays In General
 
Functions, Strings ,Storage classes in C
 Functions, Strings ,Storage classes in C Functions, Strings ,Storage classes in C
Functions, Strings ,Storage classes in C
 
Unit ii data structure-converted
Unit  ii data structure-convertedUnit  ii data structure-converted
Unit ii data structure-converted
 
Programming in c Arrays
Programming in c ArraysProgramming in c Arrays
Programming in c Arrays
 
Arrays
ArraysArrays
Arrays
 
Programming in c arrays
Programming in c   arraysProgramming in c   arrays
Programming in c arrays
 
Arrays
ArraysArrays
Arrays
 
Arrays
ArraysArrays
Arrays
 
Array and its types and it's implemented programming Final.pdf
Array and its types and it's implemented programming Final.pdfArray and its types and it's implemented programming Final.pdf
Array and its types and it's implemented programming Final.pdf
 
ARRAYS.pptx
ARRAYS.pptxARRAYS.pptx
ARRAYS.pptx
 
C Programming Unit-3
C Programming Unit-3C Programming Unit-3
C Programming Unit-3
 
Array.pptx
Array.pptxArray.pptx
Array.pptx
 
Homework Assignment – Array Technical DocumentWrite a technical .pdf
Homework Assignment – Array Technical DocumentWrite a technical .pdfHomework Assignment – Array Technical DocumentWrite a technical .pdf
Homework Assignment – Array Technical DocumentWrite a technical .pdf
 
Algo>Arrays
Algo>ArraysAlgo>Arrays
Algo>Arrays
 
Chapter-Five.pptx
Chapter-Five.pptxChapter-Five.pptx
Chapter-Five.pptx
 
Lecture 9
Lecture 9Lecture 9
Lecture 9
 
Array and Collections in c#
Array and Collections in c#Array and Collections in c#
Array and Collections in c#
 
Arrays
ArraysArrays
Arrays
 
C++ - UNIT_-_IV.pptx which contains details about Pointers
C++ - UNIT_-_IV.pptx which contains details about PointersC++ - UNIT_-_IV.pptx which contains details about Pointers
C++ - UNIT_-_IV.pptx which contains details about Pointers
 
Arrays
ArraysArrays
Arrays
 

Mais de Eng Teong Cheah

Mais de Eng Teong Cheah (20)

Monitoring Models
Monitoring ModelsMonitoring Models
Monitoring Models
 
Responsible Machine Learning
Responsible Machine LearningResponsible Machine Learning
Responsible Machine Learning
 
Training Optimal Models
Training Optimal ModelsTraining Optimal Models
Training Optimal Models
 
Deploying Models
Deploying ModelsDeploying Models
Deploying Models
 
Machine Learning Workflows
Machine Learning WorkflowsMachine Learning Workflows
Machine Learning Workflows
 
Working with Compute
Working with ComputeWorking with Compute
Working with Compute
 
Working with Data
Working with DataWorking with Data
Working with Data
 
Experiments & TrainingModels
Experiments & TrainingModelsExperiments & TrainingModels
Experiments & TrainingModels
 
Automated Machine Learning
Automated Machine LearningAutomated Machine Learning
Automated Machine Learning
 
Getting Started with Azure Machine Learning
Getting Started with Azure Machine LearningGetting Started with Azure Machine Learning
Getting Started with Azure Machine Learning
 
Hacking Containers - Container Storage
Hacking Containers - Container StorageHacking Containers - Container Storage
Hacking Containers - Container Storage
 
Hacking Containers - Looking at Cgroups
Hacking Containers - Looking at CgroupsHacking Containers - Looking at Cgroups
Hacking Containers - Looking at Cgroups
 
Hacking Containers - Linux Containers
Hacking Containers - Linux ContainersHacking Containers - Linux Containers
Hacking Containers - Linux Containers
 
Data Security - Storage Security
Data Security - Storage SecurityData Security - Storage Security
Data Security - Storage Security
 
Application Security- App security
Application Security- App securityApplication Security- App security
Application Security- App security
 
Application Security - Key Vault
Application Security - Key VaultApplication Security - Key Vault
Application Security - Key Vault
 
Compute Security - Container Security
Compute Security - Container SecurityCompute Security - Container Security
Compute Security - Container Security
 
Compute Security - Host Security
Compute Security - Host SecurityCompute Security - Host Security
Compute Security - Host Security
 
Virtual Networking Security - Network Security
Virtual Networking Security - Network SecurityVirtual Networking Security - Network Security
Virtual Networking Security - Network Security
 
Virtual Networking Security - Perimeter Security
Virtual Networking Security - Perimeter SecurityVirtual Networking Security - Perimeter Security
Virtual Networking Security - Perimeter Security
 

Último

Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
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
Victor Rentea
 

Último (20)

Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
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 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 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 ...
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 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
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
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
 
"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 ...
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 

Learn C# Programming - Nullables & Arrays

  • 1. Learn C# Programming Nullables & Arrays Eng Teong Cheah Microsoft MVP in Visual Studio & Development Technologies
  • 4. C# - Nullables C# provides a special data types, the nullable types, to which you can assign normal range of values as well as null values. For example, you can store any value from -2,147,483,648 to 2, 147,483, 647 or null in a Nullable<Int32> variable. Similarly, you can assign true, false, or null in a Nullable<bool> variable. Syntax for declaring a nullable type is as follows: < data_type> ? <variable_name> = null;
  • 6. C# - Nullables The Null Coalescing Operator(??) The null coalescing operator is used with the nullable value types and reference types. It is used for converting an operand to the type of another nullable (or not) value type operand, where an implicit conversion is possible.
  • 9. C# - Arrays An array stores a fixed-size sequential collection of elements of the same type. An array is used to store a collection of data, but it is often more useful to think of an array as a collection of variables of the same type stored at contiguous memory locations. Instead of declaring individual variables, such as number0, number1, …, and number99, you declare one array variable such as numbers and use numbers[0], numbers[1], and …, numbers[99] to represent individual variables. A specific element in an array is accessed by an index.
  • 10. C# - Arrays All arrays consist of contiguous memory locations. The lowest address corresponds to the first element and the highest address to the last element.
  • 11. C# - Arrays Declaring Arrays To declare an array in C#, you can use the following syntax: where, datatype[] arrayName;
  • 12. C# - Arrays where, - datatype is used to specify the type of elements in the array. - [ ] specifies the rank of the array. The rank specifies the size of the array. - arrayName specifies the name of the array. For example, double[] balance; Declaring Arrays
  • 13. C# - Arrays Initializing Arrays Declaring an array does not initialize the array in the memory. When the array variable is initialized, you can assign values to the array. Array is a reference type, so you need to use the new keyword to create an instance of the array. For example, double[] balance = new double[10];
  • 14. C# - Arrays Assigning Values to an Array You can assign values to individual array elements, by using the index number, like: You can assign values to the array at the time of declaration, as shown: double[] balance = new double[10]; balance[0] = 4500.0; double[] balance = { 2340.0, 4523.69, 3421.0};
  • 15. C# - Arrays You can also create and initialize an array, as shown: You may also omit the size of the array, as shown: int [] marks = new int[5] { 99, 98, 92, 97, 95}; int [] marks = new int[] { 99, 98, 92, 97, 95};
  • 16. C# - Arrays You can copy an array variable into another target array variable. In such case, both the target and source point to the same memory location: When you create an array, C# compiler implicitly initializes each array element to a default value depending on the array type. For example, for an int array all elements are initialized to 0. int [] marks = new int[] { 99, 98, 92, 97, 95}; int[] score = marks;
  • 17. C# - Arrays Accessing Array Elements An element is accessed by indexing the array name. This is done by placing the index of the element within square brackets after the name of the array. For example, double salary = balance[9];
  • 18. Demo
  • 19. C# - Arrays Using the foreach Loop In the previous example, we used a for loop for accessing each array element. You can also use a foreach statement to iterate through an array.
  • 20. Demo
  • 21. C# - Arrays There are following few important concepts related to array which should be clear to a C# programmer: - Multi-dimensional arrays - Jagged arrays - Passing arrays to functions - Param arrays - The Array Class
  • 22. C# - Arrays Multidimensional Arrays C# allows multidimensional arrays. Multi-dimensional arrays are also called rectangular array. You can declare a 2-dimensional array of strings as: or, a 3-dimensional array of int variables as: string [,] names; int [ , , ] m;
  • 23. C# - Arrays Multidimensional Arrays Two-Dimensional Arrays The simplest form of the multidimensional array is the 2-dimensional array. A 2-dimensional array is a list of one-dimensional arrays.
  • 24. C# - Arrays A 2-dimensional array can be thought of as a table, which has x number of rows and y number of columns. Following is a 2- dimensional array, which contains 3 rows and 4 columns.
  • 25. C# - Arrays Thus, every element in the array a is identified by an element name of the form a[i,j], where a is the name of the array, and i and j are the subscripts that uniquely identify each element in array a.
  • 26. C# - Arrays Initializing Two-Dimensional Arrays Multidimensional arrays may be initialized by specifying bracketed values for each row. The following array is with 3 rows and each row has 4 columns. int [,] a = new int [3,4] { {0, 1, 2, 3} , /* initializers for row indexed by 0 */ {4, 5, 6, 7} , /* initializers for row indexed by 1 */ {8, 9, 10, 11} /* initializers for row indexed by 2 */ };
  • 27. C# - Arrays Accessing Two-Dimensional Array Elements An element in 2-dimensional array is accessed by using the subscripts. That is, row index and column index of the array. For example, The above statement takes 4th element form the 3rd row of the array. You can verify it in the above diagram. int val = a[2,3];
  • 28. Demo
  • 29. C# - Arrays Jagged Arrays A Jagged array is an arrays. You can declare a jagged array named scores of type int as: int [][] scores;
  • 30. C# - Arrays Jagged Arrays Declaring an array, does not create the array in memory. To create the above array: int[][] scores = new int[5][]; for (int i = 0; i < scores.Length; i++) { scores[i] = new int[4]; }
  • 31. C# - Arrays Jagged Arrays You can initialize a jagged array as: Where, scores is an array of two arrays of integers – scores[0] is an array of 3 integers and scores[1] is an array of 4 integers. int[][] scores = new int[2][]{new int[]{92,93,94},new int[]{85,66,87,88}};
  • 32. Demo
  • 33. C# - Arrays Passing Arrays as Function Arguments You can pass an array as a function argument in C#.
  • 34. Demo
  • 35. C# - Arrays Param Array At times, while declaring a method, you are not sure of the number of arguments passed as a parameter. C# param arrays (or parameter arrays) come into help at such times.
  • 36. Demo
  • 37. C# - Arrays Array Class The Array class is the base class for all the arrays in C#. It is defined in the System namespace. The Array class provides various properties and methods to work with arrays.
  • 38. C# - Arrays Properties of the Array Class The following table describes some of the most commonly used properties of the Array class:
  • 39. C# - Arrays Methods of the Array Class The following table describes some of the most commonly used methods of the Array class:
  • 40. C# - Arrays Methods of the Array Class The following table describes some of the most commonly used methods of the Array class: