In the simplified example below, I want to determine resultbefore it will be considered. The linq queries below return lists of anonymous types. resultwill exit linq queries as IEnumerable <'a>, but I cannot define it this way at the top of the method. Am I trying to do this (in .NET 4)?
bool large = true;
var result = new IEnumerable();
List<int> numbers = new int[]{1,2,3,4,5,6,7,8,9,10}.ToList<int>();
if (large)
{
result = from n in numbers
where n > 5
select new
{
value = n
};
}
else
{
result = from n in numbers
where n < 5
select new
{
value = n
};
}
foreach (var num in result)
{
Console.WriteLine(num.value);
}
EDIT: To be clear, I know that in the above example, I don't need anonymous types. This just illustrates my question with a small simple example.
source
share