我有一個MVC登載有一個整數數組,我想爲INT的進行陣列轉換爲IEnumerable<MyTestObj>
。這是如何完成的?看來我不能使用myintArr.AsEnumerable()
。int數組到IEnumerable <MyTestObj>?
-2
A
回答
6
你需要沿着以下線的東西(這取決於你如何創建對象):
myIntArr.Select(i => new MyTestObj(i));
// or...
myIntArr.Select(i => (MyTestObj)i);
// or...
myIntArr.Select(i => new MyTestObj { SomeProperty = i });
0
我有點困惑。我假設你有這樣的事情一個動作:
public ActionResult MyAction(int [] postedValues)
如果是這樣的話,那麼postedValues
將已經IEnumerable的。不知道你有什麼問題。這不是你要求的,然後看看梅爾達德或安德烈亞斯的答案。
2
我可以在這裏失去了點,但確實不是一個陣列支持IEnumerable的?換句話說,就像原樣使用你的數組(假設你想要一個int的枚舉)。
如果你想一些其他對象的枚舉集合,我認爲其他的答案解決這一問題,但目前還不清楚(至少對我來說)它是什麼你試圖acheive。
相關問題
- 1. 分組IEnumerable <IEnumerable <int>>
- 2. 鑄造了IEnumerable <int>到IEnumerable的<long>失敗
- 3. Simply IEnumerable <int> to List <KeyValuePair <int, int>>?
- 4. 如何將IEnumerable <IEnumerable <IGrouping <int,string> >>轉換爲IEnumerable <IEnumerable <string>>
- 5. List <int> to IEnumerable <IComparable>
- 6. 如何從IEnumerable <MyClass>告訴IEnumerable <int>?
- 7. Cast a hashtable.Keys into List <int> or other IEnumerable <int>
- 8. Linq:Xml到IEnumerable <KeyValuePair <int, string>>延期執行?
- 9. 將函數Func <IList, int>轉換爲Func <IEnumerable,int>?方法
- 10. 轉換一個IEnumerable <組<TParent,年擄>>到IEnumerable <TParent>
- 11. NHibernate的ICritery添加IEnumerable <int>?
- 12. 將lambda類型從int => IEnumerable <string>>轉換爲int =>任務<IEnumerable <string> >>?
- 13. IEnumerable <>到IList <>
- 14. 空數組和IEnumerable <T>
- 15. 的EntitySet <IEnumerable的<T>>到IEnumerable的<T>
- 16. IEnumerable的<T>到的IDictionary <U,IEnumerable的<T>>
- 17. 選擇自IEnumerable <T>到IEnumerable的<Quantity<T>>
- 18. 如何將IEnumerable <IEnumerable <Foo>>減少到IEnumerable <Foo>?
- 19. IEnumerable的<IEnumerable的<T>>到的IEnumerable <T>使用LINQ
- 20. 我如何拆分一個IEnumerable <String>到IEnumerable的組<string>
- 21. 轉換/投射IEnumerable到IEnumerable <T>
- 22. C#將整數字符串拆分爲IEnumerable <int>
- 23. WPF的DataGrid結合的IEnumerable <KeyValuePair <INT,CustomType >>
- 24. JButton數組到int數組
- 25. 演員/轉換IEnumerable <T>到IEnumerable <U>?
- 26. 的Linq:轉換IEnumerable的<Point>到IEnumerable <float>
- 27. 投自IEnumerable <object>到IEnumerable的<decimal>
- 28. XML到IEnumerable的<T>
- 29. 從IEnumerable <IEnumerable <T>>
- 30. 鑄造IEnumerable <Derived> IEnumerable <BaseClass>