In simple words we can say arrays are collection of similar types of data items that shares a common name.
and arrays are reference type in c# so we can store any type of inbuilt or user defined data.
like simple variables stores single values arrays can store multiple values in their array indexes.
like if i want to store age of one person we can declare a variable as
int _age;
and give value like this--
_age=20;
but if i want to store age of five person we need five different variables and it is difficult to remember their names. so in such kind of cases where we need to store multiple data with same data type. we create arrays.
syntax:
datatype arrayname[]; //declare array
int ages[]; // declare int array
ages=new int[10]; //create the reference to allocate 10 int variable.
C# supports single-dimensional arrays, multidimensional arrays (rectangular arrays), and array-of-arrays (jagged arrays).
syntax:
Single Dimension array
syntax:
Single Dimension array
int[] numbers;
numbers=new int[10];
or
int []numbers=new int[10];
No comments:
Post a Comment