top | item 45384956

(no title)

danbruc | 5 months ago

.NET supports this because [Visual] Basic supports it. This can be used from C# - and other languages - but there is no nice syntax supporting it.

  // This also supports multidimensional arrays, that is why the parameters are arrays.
  var array = Array.CreateInstance(elementType: typeof(Int32), lengths: [ 5 ], lowerBounds: [ -2 ]);

  // This does not compile, the type is Int32[*], not Int32[].
  // Console.WriteLine(array[0]);

  array.SetValue(value: 42, index: -2);

  Console.WriteLine(array.GetValue(-2));

discuss

order