|
Delphi |
|
Array can contain any items except files:
var
IntArray: array[1..100] of Integer;
StringArray: array[0..10] of string;
You can define the array type and use it for defining the array variables:
type
IntArrayType: array[1..100] of Integer;
var
IA1,IA2: IntArrayType;
You can use any range of array index and use for it any range of any ordinal type:
var
StringArrayByChar: array[Char] of string;
IntArrayByIntRange: array[10..19] of Integer;
DoubleArrayByCharRange: array['0'..'9'] of Double;
You can create multidimentional array:
var
Table10x10: array[1..10] of array[1..10] of Boolean;
or with the same result:
var
Table10x10: array[1..10,1..10] of Boolean;
You can access any item of any array by index:
var
StringArrayByChar: array[Char] of string;
Table10x10: array[1..10,1..10] of Boolean;
...
StringArrayByChar['G']:='Greatis Software';
Table10x10[2,6]:=True;
Global array variable can be preinitialized:
var
Digits: array[0..9] of string =
('zero','one','two','three','four','five','six','seven','eight','nine');
Table2x2: array[1..2,1..2] of Integer = ((1,2),(2,4));
The dynamic arrays can be created:
var
DA: array of string;
...
SetLength(DA,10);
DA[9]:='Nine';
SetLength(DA,25);
DA[21]:='Twenty one';
// the array is destroyed automatically,
// but you can destroy it manually by
// assigning nil:
DA:=nil;
Dynamic arrays can be multidimensional too:
var
Int2D: array of array of Integer;
...
SetLength(Int2D,8,8);
|
|
C# |
|
Array can contain any items:
int[] intArray;
string[] stringArray;
Array can be initialized after creation:
int[] intArray = new int[] { 1, 2, 3, 4, 5 };
Array can be create by calling the CreateInstance static method, but this array cannot be initialized during creation:
int[] intArray = Array.CreateInstance(typeof(int), 5) as int[];
Arrays can be indexed only by integers.
Array can be multidimensional:
int [,] table = new int[2,2] {{0,1},{2,3}};
Array size cannot be changed after creation. Dynamic arrays must be realized as collections with the rich set of classes from System.Collections and System.Collections.Generic namespaces.
|
|
Arrays can be indexed only by integers. There is no easy ways to create array started from the non-zero index. |
|
|
|
The collections are the C# language feature - the dynamic arrays never were so easy in use. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|