gpt4 book ai didi

c# - 如何在 C# 文件中创建 List 实例

转载 作者:太空宇宙 更新时间:2023-11-03 20:47:48 25 4
gpt4 key购买 nike

我有这些类(class):

public class BaseGrid
{
public int current { get; set; }
public int rowCount { get; set; }
public int total { get; set; }
public List<T> rows { get; set; }
}

public class Product
{
public int Id { get; set; }
public string Name { get; set; }
}

回到我的 Controller ,我想做类似的事情:

        List<Product> listOfProducts = new List<Product>();

BaseGrid baseGrid = new BaseGrid();
baseGrid.rowCount = 10;
baseGrid.total = 20;
baseGrid.current = 1;
baseGrid.rows = listOfProducts;

我怎样才能将“行”属性变成一个通用列表,例如在运行时 baseGrid.rows 到我想要的任何列表类型?

谢谢。

最佳答案

 public class BaseGrid<T> where T : class
{
public int current { get; set; }
public int rowCount { get; set; }
public int total { get; set; }
public List<T> rows { get; set; }
}

关于c# - 如何在 C# 文件中创建 List<T> 实例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59077650/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com