C# 自定义泛型集合

2025-01-05 03:38:37
推荐回答(2个)
回答1:

我不知道你为什么要这样使用,不过你可以改成这样

Cells c=new Cells();
List r=new List();
r.add(c);
List> list = new List>();
list.add(r);

如果我说的符合你的要求,就给我分吧。- -

回答2:

class Program
{
static void Main(string[] args)
{
Cells c = new Cells();
Rows r = new Rows();
r.Add(c);
List> list = new List>();
list.Add(r);

}
}
public class Cells
{
private int cellNo;
public int CellNo
{
get { return cellNo; }
set { cellNo = value; }
}
private string cellData;
public string CellData
{
get { return cellData; }
set { cellData = value; }
}
}
public class Rows
{
private int rowNo;
public int RowNo
{
get { return rowNo; }
set { rowNo = value; }
}
private T rowData;
public T RowData
{
get { return rowData; }
set { rowData = value; }
}
public void Add(T cell)
{
rowData = cell;
}
}