I have an array of object like this
var items = new object[]
{
new {name= "house",code=1,price= 30},
new {name= "water",code=2,price= 323},
new {name= "food",code=3,price= 45}
};
I want to add each of these value into data table rows (so 1 object - 1 row) through a method which has parameter is an array of object.
I try to do like the code below but it just add each of object in my items array into a table cells in excel file (I've already added headers into my data table)
public void Create(object[] items)
{
// table headers are created before this line.......
var table = new DataTable();
table.Rows.Add(items);
}
So what I need to do, like how to loop through my array and get each of its value to assign to a row. Expected result in my file:
Name Code Price
===================
house 1 30
water 2 323
food 3 45
Thank you (and please comment if my question is not clear enough)