Take a look at following code:
Why result1 has 2 generic arguments?
public class Program
{
public static void Main(string[] args)
{
IEnumerable<Test> result1 = Test1();
Console.WriteLine(result1.GetType().GetGenericArguments().Count()); // 2
IEnumerable<Test> result2 = Test2();
Console.WriteLine(result2.GetType().GetGenericArguments().Count()); // 1
}
public static IEnumerable<Test> Test1()
{
return new Test[] { }.Where(t => t.Id > 1).Select(t =>
{
t.Id++;
return t;
});
}
public static IEnumerable<Test> Test2()
{
return new Test[] { }.Where(t => t.Id > 1);
}
}
public class Test
{
public virtual int Id { get; set; }
}
Aucun commentaire:
Enregistrer un commentaire