You can also use LINQ's query comprehension syntax, which casts to the type of the range variable (item in this example) if a type is specified:
IEnumerable list = new ArrayList { "dog", "cat" };
IEnumerable<string> result =
from string item in list
select item;
foreach (string s in result)
{
// InvalidCastException at runtime if element is not a string
Console.WriteLine(s);
}
The effect is identical to @JaredPar's solution; see 7.16.2.2: Explicit Range Variable Types in the C# language specification for details.