foreach 与 LINQ .ForEach()
foreach vs LINQ .ForEach()
为什么LINQ .ForEach
需要一个List
对象,而foreach
语句只需要IEnumerable
?
我更喜欢在多行时使用 foreach
,在单行语句中使用 LINQ - 只是为了提高可读性。
但是什么是首选,为什么?为什么不同?
没有 Linq ForEach()
方法。您正在查看的方法是 a member of List<T>
.
See here for a discussion on why Linq/IEnumerable doesn't have ForEach()
.
为什么LINQ .ForEach
需要一个List
对象,而foreach
语句只需要IEnumerable
?
我更喜欢在多行时使用 foreach
,在单行语句中使用 LINQ - 只是为了提高可读性。
但是什么是首选,为什么?为什么不同?
没有 Linq ForEach()
方法。您正在查看的方法是 a member of List<T>
.
See here for a discussion on why Linq/IEnumerable doesn't have ForEach()
.