I have a list containing some values.
Example:
List<object> testData = new List <object>();
testData.Add(new List<object> { "aaa", "bbb", "ccc" });
testData.Add(new List<object> { "ddd", "eee", "fff" });
testData.Add(new List<object> { "ggg", "hhh", "iii" });
And I have a class like
class TestClass
{
public string AAA {get;set;}
public string BBB {get;set;}
public string CCC {get;set;}
}
How to convert testDatato type List<TestClass>?
Is there a way to convert other than this?
testData.Select(x => new TestClass()
{
AAA = (string)x[0],
BBB = (string)x[1],
CCC = (string)x[2]
}).ToList();
I do not want to mention column names, so I can use this code regardless of class changes.
I also have IEnumerable<Dictionary<string, object>>one that has data.
source
share