Hi, Welcome to all. My name is Abdul Yesdani. Today we are going to learn about arrays in C#.
In our previous postings we have worked with variables. One variable can store only one value. If we want to store multiple values of same type, array variable is there to do that job.
What is an array?
An array variables is capable of storing multiple values of same type.
Syntax: datatype[ ] arrayName = new datatype[size];
Example: int [ ] myNumbers = new int [ 5];
The above array variable myNumbers is capable of storing 5 integer values.
In the memory it will allocate 5 slots to store 5 values, index starting from 0 to 4. Array indexing will always start with 0 and end with size -1.
Types of Arrays in C# :
There are 3 types of array in C#. Single dimensional array, multi dimensional array and jagged array.
Single dimension array represent a single column or row of values. The above example is for the same.
example: int [ , ] twoDarray = new int[3,4]; We can print 3 rows with 4 columns matrix.
example: int [ ][ ] jaggedarray = new int[3][ ];
jaggedarray[0]= new int[3]{34,45,56};
jaggedarray[1] = new int[2 ] {33,99};
jaggedarray[2]= new int[5 ] {10,20,30,40,50};
watch video
Good, please post content regularly.
ReplyDelete