Compact list conversion using LINQ

This is my code:

 List<bool> results1 = new List<bool>();
 List<int> items1 = ...;
 foreach (var item in items1)
     results1.Add((item >= 1600 && item <= 5000));

I'm sure this can be compacted into one line, but how?

Answers


results1 = items1.Select(i => i >= 1600 && i <= 5000).ToList();


ConvertAll doesn't change the original list. In order to make this one-liner, you probably should substitute items1 with the code ... where you get your items, if you are not using it somewhere else.

 List<bool> results1 = items1.ConvertAll(i => i >= 1600 && i <= 5000);

Need Your Help

type mismatch with @helper

java playframework playframework-2.0

I'm trying to show a form with the values but it's not working.

Using Silvlight, custom EF POCO, custom Validation - leveraging Metadata and its not working in Silverlight 4

silverlight reflection metadatatype

I am using metadata validation for both my MVC and SIlverlight together. However, the classes for silverlight arent working, and I think its due to the MetadataTypeAttribute that doesn't exist for