tags:

views:

83

answers:

1

How do I specify the type of the range variable in a linq query?

+5  A: 

Just declare it with the variable itself:

var query = from string text in collection
            where text.Length > 5
            select text.ToUpper();

This will translate to:

var query = collection.Cast<string>()
                      .Where(text => text.Length > 5)
                      .Select(text => text.ToUpper());
Jon Skeet