我对 mscorlib 进行了快速检查,结果如下;
命名空间下System.Collections;
ArrayList
BitArray
HashTable
IDictionary, hence all the implementations.
IList, hence all the implementations.
SortedList
在命名空间System.Collections.Generic下
Dictionary<T, T>
IDictionary<T, T>, hence all the implementations.
IList<T>, hence all the implementations.
IReadOnlyDictionary<T, T>, hence all the implementations.
IReadOnlyList<T>, hence all the implementations.
List<T>, hence all the implementations.
你也有数组。
但是,我建议您为您的特定任务使用自定义类。
您需要提供有关 x、y 处的 Grid 元素或对象的信息。这取决于用户吗?是你提供的吗?
这是一个简单的通用方法。
class GridManager<T>
{
private T[,] _matrix;
public GridManager(int rows, int columns)
{
_matrix = new T[rows, columns];
}
public T this[int i, int j]
{
get
{
return _matrix[i, j];
}
set
{
_matrix[i, j] = value;
}
}
}