A one-dimensional array. : Array « Data Structure « C# / CSharp Tutorial






An array is a collection of variables of the same type that are referred to by a common name.

To declare a one-dimensional array, you will use this general form:

type[ ] array-name = new type[size];
using System; 
 
class MainClass {  
  public static void Main() {  
    int[] sample = new int[10]; 
    int i;  
  
    for(i = 0; i < 10; i = i+1)  
      sample[i] = i; 
 
    for(i = 0; i < 10; i = i+1)  
      Console.WriteLine("sample[" + i + "]: " + 
                         sample[i]);  
  }  
}
sample[0]: 0
sample[1]: 1
sample[2]: 2
sample[3]: 3
sample[4]: 4
sample[5]: 5
sample[6]: 6
sample[7]: 7
sample[8]: 8
sample[9]: 9








11.1.Array
11.1.1.A one-dimensional array.
11.1.2.Declaring and Accessing an Array
11.1.3.Initializing Anonymous Type Arrays
11.1.4.System.Array is a base class for all arrays in C#
11.1.5.Methods Defined by Array
11.1.6.Declare the array and instantiate the array
11.1.7.Set array element value by index(subscript)
11.1.8.Array Declaration with initialization
11.1.9.Use for each loop to output elements in an array
11.1.10.Array Inherited Members: get array type
11.1.11.Array Inherited Members: Rank and Length
11.1.12.Array Inherited Members: GetLength(0)
11.1.13.Use ArraySegment to store string array
11.1.14.Array.SequenceEqual