List<MyClass> SampleList = new List<MyClass>() { new MyClass(), new MyClass(), new MyClass() };
string AggCount = SampleList.Aggregate((counter, next) => counter.f_ToString() += next.f_ToString());
}
}
internal class MyClass
{
public string f_ToString()
{
Random rnd = new Random();
return rnd.Next(1000).ToString();
}
}
Q
聚合函數問題
1
A
回答
2
它看起來像你H請撥打MyClass
的清單,名稱爲SampleList
,對於每個項目,您都需要撥打f_ToString
,然後爲其創建一個字符串。你並不真的需要Aggregate
,試圖(對.NET 4.0):
string agg = String.Concat(SampleList.Select(myClass => myClass.f_ToString()));
基於.NET 3.5是需要的毗連一個數組,所以這將是:
string agg = String.Concat(
SampleList.Select(myClass => myClass.f_ToString()).ToArray()
);
如果你還是想使用Aggregate,雖然這裏沒有很好的理由,應該寫成:
string agg = SampleList.Aggregate("",
(counter, next) => counter + next.f_ToString());
注意counter
這裏是一個字符串,所以你不能叫f_ToString
在上面。
作爲最後一點,我會熱烈地建議您爲變量選擇更好的名稱。
1
您嘗試將值賦給方法f_ToString()。更換+ =與+
int AggCount = SampleList.Aggregate((counter, next) => counter.f_ToString() + next.f_ToString());
1
從
int AggCount = SampleList.Aggregate((counter, next) => counter.f_ToString() += next.f_ToString());
變化
int AggCount = SampleList.Aggregate((counter, next) => counter.f_ToString() + next.f_ToString());
becus u使用賦值運算符,而不是CONCAT字符串
相關問題
- 1. MySQL聚合函數問題
- 2. 聚合函數和按問題分組
- 3. 三用聚合函數問題加入
- 4. MongoDb php的聚合函數問題
- 5. 凡/有上聚合函數問題
- 6. 問題與聚合函數R
- 7. 使用DISTINCT函數的SQL聚合函數問題
- 8. 聚合函數
- 9. 聚合函數
- 10. 聚合函數
- 11. MySQL聚合問題
- 12. DataTable聚合問題
- 13. 聚合根問題
- 14. Django的聚合函數問題(計數= -number-)
- 15. SQL Server:聚合函數難題
- 16. 聚合函數(GUID)
- 17. SQL聚合函數
- 18. 聚合函數由
- 19. SQL聚合函數
- 20. 與聚合函數
- 21. SQL聚合函數
- 22. ElasticSearch聚合函數
- 23. SQL聚合函數
- 24. Neo4j聚合函數
- 25. 與聚合函數
- 26. jooq聚合函數
- 27. 與聚合函數
- 28. 函數集合中的函數聚合
- 29. 訪問SQL查詢聚合函數
- 30. Neo4j - 不能在聚合函數裏面使用聚合函數
你究竟在做什麼? – LukeH 2010-12-07 13:05:41
你的問題實際上是什麼?這個消息實際上是非常明確的:你不能使用調用方法作爲你想要分配的東西 – PierrOz 2010-12-07 13:06:17