How To Use Array In C#, How To Declare Array, What is Array-
* An array is a driven DataType That is Kind of Storage.
* An array is a Storage and Collection Type.
Array Types
Arrays can be divided into the following four categories.
Important Points To Learn-
- In C#, an array index starts at zero. That means the first item of an array starts at the 0th position.
- The position of the last item in an array will total the number of items - 1.
- if an array has 10 items, the last 10th item is at 9th position
- In C#, arrays can be declared as fixed length or dynamic.
- A dynamic array does not have a predefined size.
How To Declare An Array -(ऐरे के केसे बनाते है)
-------First Type of Array
--------[ ] (shows Size of Array in Case of Fixed Size)
--------Name Of Array
For Example - Int [] Arr;
Explain- This is an Array that type is Int and Name is Arr.
Dynamic array of integer types
int[] intArray;
- int[] intArray;
- intArray = new int[5];
This is An Array with size 5,
Their index are [0],[1],[2],[3],[4]
How To Fill An Array(array में डाटा केसे डाले)-
string[] strArray = new string[] { "Mahesh Chand", "Mike Gold", "Raj Beniwal", "Praveen Kumar", "Dinesh Beniwal" };
How To Access Array Data (array के डाटा को use केसे करें )-
We can access an array item by passing the item index in the array. The following code snippet creates an array of three items and displays those items on the console.
- // Initialize a fixed array one item at a time
- int[] staticIntArray = new int[3];
- staticIntArray[0] = 1;
- staticIntArray[1] = 3;
- staticIntArray[2] = 5;
- // Read array items one by one
- Console.WriteLine(staticIntArray[0]);
- Console.WriteLine(staticIntArray[1]);
- Console.WriteLine(staticIntArray[2]);
This method is useful when you know what item you want to access from an array. If you try to pass an item index greater than the items in array, you will get an error().
No comments:
Post a Comment