如何将list里的数据与另一个list里的数据替换

List listdate = new List();

        List<object[]> list = new List<object[]>();

        foreach (DataGridViewCellCollection row in dataGridView1.Rows.OfType<DataGridViewRow>().Select(vR => vR.Cells))
        {
            List<object> rowData = new List<object>();
            foreach (DataGridViewCell cell in row)
            {
                rowData.Add(cell.Value);
            }
            list.Add(rowData.ToArray());
        }

linq select转换下即可


            List<DeviceConfig> listdate = dataGridView1.Rows.OfType<DataGridViewRow>().Select(vR =>
           {
               var app = new DeviceConfig();
               app.No = vR.Cells[0].Value.ToString();
               app.Type = vR.Cells[1].Value.ToString();
               app.Ip = vR.Cells[2].Value.ToString();
               app.Port = int.Parse(vR.Cells[3].Value.ToString());
               app.SlaveId = vR.Cells[4].Value.ToString();
               app.ParamAddress = vR.Cells[5].Value.ToString();
               app.ReceiveInternal = 3000;//那就默认成配置文件一样的值 vR.Cells[6].Value.ToString();//ReceiveInternal这个属性对应哪列?后面4列  对应DATARule,
               app.DATARule = new List<Rule> {
                new Rule{
                DataStart=vR.Cells[6].Value.ToString(),
                DataEnd=vR.Cells[7].Value.ToString(),
                ErrorDataStart=vR.Cells[8].Value.ToString(),
                ErrorDataEnd=vR.Cells[9].Value.ToString()
                }
               };

               return app;
           }).ToList();

定义一个中间List变量,用来做交换。

您好,我是有问必答小助手,您的问题已经有小伙伴帮您解答,感谢您对有问必答的支持与关注!
PS:问答VIP年卡 【限时加赠:IT技术图书免费领】,了解详情>>> https://vip.csdn.net/askvip?utm_source=1146287632