Toubi
Toubi

Reputation: 2509

getting array of arrays from List using lambda?

I am trying to query data from List with Lambda expression. Below is my Users class

Users

 Id,Name,Password, EmailAddress

Required data would be an array of arrays using two columns from list Name and password .Select(c => c.LastUpdatedDate + "," + c.LastUpdatedDate ).ToArray();. Result wold be something like belwo:

[["Name1","***"],["Name2","+++"],["Name3","///"]]

Can you please guide and help me selecting this.

Upvotes: 2

Views: 2961

Answers (1)

McGarnagle
McGarnagle

Reputation: 102783

You can do this by creating a new array inside a Linq Select (I assume you want an object array since you have an int and string in there):

object[][] result = users.Select(user => new object[] { user.Id, user.Name }).ToArray();

If both columns are string, then the syntax is almost identical -- just replace both object[] with string[]:

string[][] result = users.Select(user => new string[] { user.Id, user.Name }).ToArray();

Upvotes: 5

Related Questions