Creating an object with dynamic properties in C #

I use linq to load the csv file, but since csv can have any number of columns, the returned object will have dynamic properties, and I cannot figure out how to do this.

var data = from row in csvData
       let col = row.Split(',')
       select new
              {
                  Field1 = data[0],
                  Field2 = data[1],
                  Field3 = data[2] // etc, etc
              };

If possible, I would like to name the properties by the name specified in the csv file, and not in field1, field2, etc.

Thank!

+5
source share
2 answers

? .NET 4, ExpandoObject - , , , . (.. ), Dictionary<string, string>?

+7

All Articles