MVK MVK - 3 years ago 131
C# Question

How can i achieve this in LINQ-Queries?

List<double> Values = new List<double>();
foreach (var item in Level.Items)
{
Values.Add(item.Keys);
}


I'm new for LINQ-Queries, So can anyone help how to write the above codes in LINQ-Queries.

Answer Source

Try this:

List<double> Values = new List<double>(Level.Items.Select(item => item.Keys));

Or

List<double> Values = Level.Items.Select(item => item.Keys).ToList();

In case you have to add items into existing list:

List<double> Values = new List<double>();

...

Values.AddRange(Level.Items.Select(item => item.Keys));
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download