dotnet / dotnet/dotnet-api-docs

Multidimensional arrays in ArrayList?

Open
#862 1 comment 0 reactions 0 assignees View on GitHub
area-System.Collections dotnet-api/prod Pri2 untriaged
Dominant language
C#
Stars
949
Forks
1.7k
Avg merge
3d 27m
Merged PRs (30d)
49

Description

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.*

* ID: 9fa6e8e6-c711-8423-a1b9-3ad1e51484ad
* Version Independent ID: 7400ed93-312d-9193-5eb4-512551cb66d9
* Content: [ArrayList Class (System.Collections)](https://docs.microsoft.com/en-us/dotnet/api/system.collections.arraylist?redirectedfrom=MSDN&view=netframework-4.7.2#methods)
* Content Source: [xml/System.Collections/ArrayList.xml](https://github.com/dotnet/dotnet-api-docs/blob/master/xml/System.Collections/ArrayList.xml)
* Product: **dotnet-api**
* GitHub Login: @mairaw
* Microsoft Alias: **mairaw**

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.