dotnet / dotnet-api-docs

.NET API reference documentation (.NET 5+, .NET Core, .NET Framework)
https://docs.microsoft.com/dotnet/api/
Other
687 stars 1.52k forks source link

Multidimensional arrays in ArrayList? #862

Open MikeRosoft opened 5 years ago

MikeRosoft commented 5 years ago

The documentation says: "Using multidimensional arrays as elements in an ArrayList collection is not supported." What exactly does this mean? The following code:

var arrayList = new System.Collections.ArrayList(); var item = new int[2, 2] { { 1, 2 }, { 3, 4 } }; arrayList.Add(item);

... normally adds the array to the list. The parameter of ArrayList.Add(value) is object, so it supports adding any object to the list; specifically disallowing multidimensional arrays would seem like an arbitrary limitation. (The elements of the inner array can be retrieved by casting the element, like this: ((int[,])arrayList[0])[1,0] .)


Document Details

Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

mairaw commented 5 years ago

@safern, @ianhays can you comment on this? Are multidimensional arrays supported but not recommended?