C# ArraysLike other programming languages, array in C# is a group of similar types of elements that have contiguous memory location. In C#, array is an object of base type System.Array. In C#, array index starts from 0. We can store only fixed set of elements in C# array. Advantages of C# Array
Disadvantages of C# Array
C# Array TypesThere are 3 types of arrays in C# programming:
C# Single Dimensional ArrayTo create single dimensional array, you need to use square brackets [] after the type. You cannot place square brackets after the identifier. Let's see a simple example of C# array, where we are going to declare, initialize and traverse array. Output: 10 0 20 0 30 C# Array Example: Declaration and Initialization at same timeThere are 3 ways to initialize array at the time of declaration. We can omit the size of array. We can omit the new operator also. Let's see the example of array where we are declaring and initializing array at the same time. Output: 10 20 30 40 50 C# Array Example: Traversal using foreach loopWe can also traverse the array elements using foreach loop. It returns array element one by one. Output: 10 20 30 40 50 Next TopicC# Passing Array to Function |
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India