2

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.

1 Answer 1

5

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();
Sign up to request clarification or add additional context in comments.

3 Comments

thanks, it really helped me. Just a small edit please, what if both columns are string.
+1. Depending on types of fields instead of user => new object[]... you can use user => new string[]... or just user => new[]...
@Toubi it's almost the same, see my edit, and also Alexei's note (implicitly-typed arrays)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.