Say you have a list of Object person:
private List<Person> lstPersons = new List<Person>();
In which person is defined as:
public class Person
{
public string Name { get; set; }
public int Age { get; set; }
public string Mail { get; set; }
}
Can you use Linq to return a multidimensional array from the mentioned list in which the first dimension is index of record, the second dimension is name and the third dimension is email?
Well you can create an object[][]
, yes:
object[][] array = people.Select((p, index) => new object[] { index, p.Name, p.Mail })
.ToArray();
If you wanted an object[,]
, that's not doable with regular LINQ as far as I'm aware.
If you have the choice though, I'd personally use an anoymous type:
var projected = people.Select((p, index) => new { Index = index, p.Name, p.Mail })
.ToArray();
It depends on what you want to do with the result, of course...
See more on this question at Stackoverflow