【发布时间】:2017-07-03 20:49:31
【问题描述】:
这行不行:
public List<T> GetTypes(Type type) => new List<T>().AddRange(
elements.ForEach(x => x.GetType() == type)
);
错误 CS0201 只有赋值、调用、递增、递减和新对象表达式可以作为语句使用
【问题讨论】:
-
elements.ForEach(x => x.GetType() == type) 不返回一个列表,你的意思是在哪里?
-
AddRange不返回值。你的意思是elements.Where(x => x.GetType() == type).ToList()? -
使用
List<T>(IEnumerable<T>) constructor instead of the parameterless constructor. Or use a LINQ query followed by aToList()` -
@Emily,看看this 解决方案是否适合你...