Cod*_*lus 0 c# arrays constructor struct initialization
我有理想的数据表示如下:
LinkedList<T>[]
Run Code Online (Sandbox Code Playgroud)
但是,你不能在泛型上做到这一点,所以我把它包装在一个结构中:
public struct SuitList
{
LinkedList<T> aList;
public SuitList()
{
aList = new LinkedList<T>();
}
}
Run Code Online (Sandbox Code Playgroud)
现在,在我的班上,我有
SuitList[] myStructList; //there is only 4 indices of myStructList
Run Code Online (Sandbox Code Playgroud)
如何在类的构造函数中初始化aList?我试过这个如下:
myStructList = new SuitList[4];
for(int i = 0; i < 4; i++)
{
myStructList[i] = new SuitList();
}
Run Code Online (Sandbox Code Playgroud)
编译器给了我一个错误,说Structs不能包含显式无参数构造函数.有更好的方法吗?我在这里先向您的帮助表示感谢.
| 归档时间: |
|
| 查看次数: |
513 次 |
| 最近记录: |