C# 错误无法从';GameLibrary.GamePlayLoader2.WinningLinesParent';至';int';
这就是我有转换错误的地方。新WinningLinesParent(0,num,num2,list,list2)C# 错误无法从';GameLibrary.GamePlayLoader2.WinningLinesParent';至';int';,c#,C#,这就是我有转换错误的地方。新WinningLinesParent(0,num,num2,list,list2) public WinningLinesParent(int-id,int-rowForCol\u 0,int-rowForCol\u 1,列表行由first2rows共享,列表行由first3rows共享) { 这个.Id=Id; this.RowForCol\u 0=RowForCol\u 0; this.RowForCol_1=RowForCol_1; this.LinesShar
public WinningLinesParent(int-id,int-rowForCol\u 0,int-rowForCol\u 1,列表行由first2rows共享,列表行由first3rows共享)
{
这个.Id=Id;
this.RowForCol\u 0=RowForCol\u 0;
this.RowForCol_1=RowForCol_1;
this.LinesSharedByFirst2Rows=LinesSharedByFirst2Rows;
this.LinesSharedByFirst3Rows=LinesSharedByFirst3Rows;
}
受保护的void buildWinningLineParents()文件
{
清单2;
int num=0;
int num2=0;
列表=新列表{2,13,0x15,0x16};
list2=新列表{
13,
0x16,
新WinningLinesParent(0,num,num2,list,list2)
};
}
您正在尝试向列表中添加一个WinningLinesParent
。你认为这会怎样
列表
只能包含整数。如果您想要包含WinningLinesParent的内容,我强烈怀疑您不应该构建一个列表
与之前的文章一样,您在初始化变量之前声明变量,并且在分配变量之前尝试使用该变量(使用list2
作为WinningLinesParent
构造函数的参数)
在这篇文章和你之前的文章之间,我郑重建议你退一步,想想你想要实现什么,并确保你理解List
的用途。int类型的列表不能将WinningLinesParent添加到它的元素中(它不是int类型),因此,错误是很正常的。你的代码没有意义-你不能将WinningLinesParent
放入列表中-你想实现什么?
public WinningLinesParent(int id, int rowForCol_0, int rowForCol_1, List<int> linesSharedByFirst2Rows, List<int> linesSharedByFirst3Rows)
{
this.Id = id;
this.RowForCol_0 = rowForCol_0;
this.RowForCol_1 = rowForCol_1;
this.LinesSharedByFirst2Rows = linesSharedByFirst2Rows;
this.LinesSharedByFirst3Rows = linesSharedByFirst3Rows;
}
protected void buildWinningLineParents()
{
List<int> list2;
int num = 0;
int num2 = 0;
List<int> list = new List<int> { 2, 13, 0x15, 0x16 };
list2 = new List<int> {
13,
0x16,
new WinningLinesParent(0, num, num2, list, list2)
};
}