Open array parameters |
Top Previous Next |
What is translated > Types > Arrays > Array parameters > Open array parameters
The concept of open arrays allow arrays of different sizes to be passed to the same procedure or function.
function Sum(Arr: Array of Integer): Integer; var i: Integer; begin Result := 0; for i := Low(Arr) to High(Arr) do Result := Result + Arr[i]; end;
In the C# translation the array member functions GetUpperBound and GetLowerBound are used instead of the Delphi functions High and Low.
public static int Sum(int[] Arr) { int result = 0; int i = 0; int stop = 0; result = 0; for(stop = Arr.GetUpperBound(0), i = Arr.GetLowerBound(0); i <= stop; i++) { result = result + Arr[i]; } return result; }
A temporary set of values can be passed as open array parameter too:
procedure Log(strings : array of string) begin end;
procedure foo; begin Log(['one', 'two', 'three']); end;
->
public static void Log(string[] strings) { }
public static void foo() { Log(new string[]{"one", "two", "three"}); }
|
This page belongs to the Delphi2C# Documentation |
Delphi2C# home Content |