如何在C#中获取列表的特定值的值

var ctsDB = mooe.Files66.ToList();
Dictionary<string,string> mappedfields = new Dictionary<string,string>();
Dictionary<string,string> ctsfieldsValue = new Dictionary<string,string>();

for (int i = 0; i < ctsDB.Count; i++)
{
    foreach(var item in mappedfields) {
        // this line returns the item.key string not the value of it. 
        // item.key is the column name
        var rowValue = mooe.Files66.Select(k = >item.Key).ToList();

        // ctsfieldsValue.Add(item.Value,rowValue);
        ctsfieldsValue.ToList();
    }
}  

我想遍历ctsDB列表并获取特定行的值 这样的列:

if ctsDB [i] =  fileID  Field612  Fiel613

我在ctsfieldsValue的value字段中有这些列名称。

我想迭代ctsDB[i]仅获得列Field612的值。 任何人都可以提供想法吗?

libailiang 回答:如何在C#中获取列表的特定值的值

var ctsDB = mooe.Files66.ToList();
var mappedfields = new Dictionary<string,string>(); // I assume this is not empty in your real code.

var ctsfieldsValue = new List<Dictionary<string,string>>();

foreach (var row in ctsDB)
{
    var d = new Dictionary<string,string>();
    foreach (var mapping in mappedfields)
    {   
        var v = row[mapping.Key]; //throws if not found
        d[mapping.Value] = v;
    }
    ctsfieldsValue.Add(d);
}
本文链接:https://www.f2er.com/3134414.html

大家都在问