typeof (Type).GetMethods().Select(x=>Console.WriteLine(x));
编译错误显示
Error 1 The type arguments for method 'System.Linq.Enumerable.Select<TSource,TResult>(System.Collections.Generic.IEnumerable<TSource>, System.Func<TSource,TResult>)' cannot be inferred from the usage. Try specifying the type arguments explicitly.
我是想循环打印GetMethods()的结果,不想自己写个for循环,因此尝试了一下Linq。这个错误是什么含义,改如何改呢?
------解决思路----------------------
Console.WriteLine(x)返回类型是void
Select()无法推断此类型
typeof (Type).GetMethods().ToList().ForEach(x=>Console.WriteLine(x));
------解决思路----------------------
推断不出 参数类型,还是用循环吧
------解决思路----------------------
List<T>有ForEach方法,可以先转成List<MethodInfo>。
typeof(Type).GetMethods().ToList().ForEach(x => Console.WriteLine(x));