Reputation: 11652
How to select properties in the order from List object using Linq?
public class Test
{
public int A { get; set; }
public string B { get; set; }
public DateTime C { get; set; }
public float D { get; set; }
}
for example List<Test>
test1, so I want to the properties in the order of C,D,B,A from LINQ selection. How can we do that?
I am doing this for epplus excel package. which reads the in the list.
var dataRange = wsData.Cells["A1"].LoadFromCollection(
from s in list
select s,
true,
OfficeOpenXml.Table.TableStyles.Medium2);
Upvotes: 0
Views: 144
Reputation: 726579
If you would like to add properties of Test
class as columns to some other columns (true
, Medium2
) you need to make an anonymous type for it:
var dataRange = wsData.Cells["A1"].LoadFromCollection(
from s in list
select new {
s.C
, s.D
, s.B
, s.A
, Flag=true
, OfficeOpenXml.Table.TableStyles.Medium2
}
);
Upvotes: 1