C# Array - c# - c# tutorial - c# net




What is an array in C# ?

  • In general, an arrays are collections of data.
  • A scalar variable can hold the only one item at a time.
  • Arrays can hold multiple items. These items are called elements of the array. Arrays store data of the same data type.
  • Each element can be referred to by an index.
  • Arrays are zero based. The index of the first element is zero. Arrays are reference types.
 c# Array

Syntax:

datatype[] arrayName;
click below button to copy the code. By - c# tutorial - team

Syntax Explanation:

  • datatype:
    Datatype is used to specify the type of elements in the array. And [ ] specifies the rank of the array. The rank specifies the size of the array.
  • arrayName:
    ArrayName specifies the name of the array.
C# Array

c# Array

C# Sample Code - C# Examples:

using System;
usingSystem.Collections.Generic;
usingSystem.Linq;
usingSystem.Text;

namespace Wikitechy_Array
{
classProgram
    {
staticvoid Main(string[] args)
        {
int[] array = newint[4];

array[0] = 1;
array[1] = 2;
array[2] = 3;
array[3] = 4;

for (inti = 0; i< 5; i++)

            {
Console.WriteLine(array[i]);
            }

Console.ReadLine();
        }
    } 
}
click below button to copy the code. By - c# tutorial - team
 Array Structure
  1. int[] array = newint[4];We declare and initialize a numerical array. And we declare an array which contains 4 elements. All elements are integers.
  2. We initialize the array with some data. This is assignment initialization. The indexes are in the square brackets. Array [0] is going to be the first element of the array.Array [1] is going to be the second element of the array, Array [2] is going to be the third element of the array, Array [3] is going to be the fourth element of the array.
  3. Here for (int i = 0; i<5; i++) specifies integer i = 0, which means the expression, (I < 5), is true. Therefore, the statement is executed, and i gets incremented by 1 and becomes 4.
  4. Here we can declare and initialize an array in one statementarray[i].
Related Tags: kurs c# , c# programmieren , tutorial c# visual studio , learn programming with c# , c# kurs online , the best way to learn c# , c# tutorial for complete beginners from scratch , tuto c# , manual c#

Sample C# examples - Output :

 Array Structure
  1. Here in this output the 1,2,3,4 will be printed until it reaches the less than "5" array elements.
Related Tags: kurs c# , c# programmieren , tutorial c# visual studio , learn programming with c# , c# kurs online , the best way to learn c# , c# tutorial for complete beginners from scratch , tuto c# , manual c#

Array Vs ArrayList :

learn c# tutorials - array vs arraylist in c#

learn c# tutorial - array vs arraylist csharp in c# Example

learn csharp tutorial - c# collections - c# example programs

learn csharp tutorial - c# collections - c# example programs

learn c# - c# tutorial - c# array class - c# examples -  c# programs
learn c# - c# tutorial - c# array class - c# examples -  c# programs


Related Searches to C# Array