Create Array from specified Type and length, with zero-based indexing in CSharp

Description

The following code shows how to create Array from specified Type and length, with zero-based indexing.

Example


using System;/*from  w  ww.ja v a  2  s.  co  m*/
public class SamplesArray  {

   public static void Main()  {

      Array my1DArray=Array.CreateInstance( typeof(Int32), 5 );
      for ( int i = my1DArray.GetLowerBound(0); i <= my1DArray.GetUpperBound(0); i++ ){
         my1DArray.SetValue( i+1, i );
      }
      
      foreach(int i in my1DArray){
         Console.WriteLine(i);
      }
   }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    Data Types »




C# Data Types
Bool
Byte
Char
Decimal
Double
Float
Integer
Long
Short
String
C# Array
Array Example
Byte Array
C# Standard Data Type Format
BigInteger
Complex
Currency
DateTime
DateTimeOffset
DateTime Format Parse Convert
TimeSpan
TimeZone
Enum
Null
tuple
var