0

Could anyone please help with the following:

If I have a list declared as follows:

List<(uint u, string s)> list1 = new List<(uint u, string s)>();

Is there a succinct LINQ statement that could extract a list of the uints in my list?

For example, if my list was initialised as:

list1.Add((1,"One"));
list1.Add((2,"Two"));
list1.Add((3,"Three"));

How could I crate a List containing the numbers {1,2,3}

At the moment I create an array of uints an loop through the array, but how could this be done using LINQ?

Thanks for any help, Mitch.

1 Answer 1

2

Use a Select for projection and ToList to accumulate to a list.

var result = list1.Select(x => x.u).ToList();
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks very much for such a quick response. Works perfectly.

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.