2011-12-07 91 views
-1
foreach (int i in temp) 
    data.Add(i); 

其中tempListdataObservableCollectionLINQ - 转换为Lambda表达式

+1

为什么你需要将其转换为拉姆达?有什么特别的原因吗? –

+0

仅供参考,拉姆达不是缩写或任何东西。它甚至不是一个专有名词,它只是“lambda” –

回答

0
temp.ForEach(x => data.Add(x)); 
0
// if data is empty just pass temp in the constructor 
ObservableCollection<int> data = new ObservableCollection<int>(temp); 

// if data already has values you can do this using List.ForEach method 
// but this would not be a LINQ since LINQ not able to modify data sources itself 
temp.ForEach(i => data.Add(i)); 
+0

除此之外的任何其他可能性?我不想使用foreach,因为它具有“foreach”语句的相同行为 –

+0

什么exacly你想实现?我对lambda需求有点困惑,你需要将它作为委托传递给某种方法,或者只是简化代码块?如果是后者 - 就像在你的问题中一样使用foreach循环 – sll

1

为什么你不只是做

var data = new ObservableCollection(temp);