Herry_zzz 2021-07-21 19:09 采纳率: 0%
浏览 65

C#里面List遍历,怎么简化

比如
这个item是另一个list,list里面又是一个类。
class Detail

public int Id { get; set; }
public string Name{ get; set; }
public string Value{ get; set; }

          List<Detail> item = db.QueryDetail(detailIn);

            DgvTest.Rows.Add();
            DgvTest.Rows[i].Cells[0].Value = item[i].Id;
            DgvTest.Rows[i].Cells[1].Value = item[i].Name;
            DgvTest.Rows[i].Cells[2].Value = item[i].Value;


能不能简化以上的代码
  • 写回答

1条回答 默认 最新

  • zxpei 2021-07-22 08:45
    关注

    你的DGV可以直接绑定item为数据源了

    DgvTest.DataSource=item;

    评论

报告相同问题?

问题事件

  • 创建了问题 7月21日