-6
A
回答
4
var oList = (IList<object>)sList.Cast<object>().ToList();
1
IList<string> s = new List<string>() ;
IList<object> o = new List<object>();
foreach (string x in o)
s.Add(x);
1
下應該這樣做:
IList<String> strings = new List<String> { "a", "b", };
IList<Object> objects = strings.Cast<Object>().ToList();
您可以通過撥打測試中LinqPad結果:objects.Dump();
0
stringList.Select(x => (object)x).ToList();
0
這正是Lambda expressions是。 您可以使用簡單的Lambda表達式進行轉換。只要你在.NET 2.0或以上版本。 如:
stringList.Select(x => (object)x).ToList();
相關問題
- 1. 使用LINQ,如何將IList <IList <object>>轉換爲IList <object>?
- 2. 將IList <T1>轉換爲IList <BaseT1>
- 3. 將IList <string>轉換爲列表<string>()
- 4. 將IList <T>轉換爲BindingList <T>
- 5. 如何將IList <Object>轉換爲JsonArray?
- 6. 如何實例化嵌套IList <T>的IList <T>?
- 7. 如何初始化IList <IList <string>>?
- 8. 將T轉換爲IList
- 9. IEnumerable <>到IList <>
- 10. 你爲什麼不能自IList <IParent>轉換爲IList的<IChild>其中ICHILD實現IParent
- 11. 將通用IList <CustomType>轉換爲數組?
- 12. 不能隱式地將void類型轉換爲IList <int>
- 13. IList <InterfaceType>爲List <ImplementsInterfaceType>?
- 14. 將函數Func <IList, int>轉換爲Func <IEnumerable,int>?方法
- 15. AutoMapper:複製的IList <>到的IList <>
- 16. Binding Gridview to IList <BusinessObject>包含IList <BusinessObject>
- 17. 的IList <T>和列表<T>轉換與接口
- 18. 轉換字典<MyType> .ValueCollection to IList <MyType>
- 19. 爲什麼Socket.Select(...)需要IList而不是(也)IList <Socket>?
- 20. JSON.NET反序列化錯誤轉換爲IList <string>
- 21. 從另一個IList <>
- 22. nHibernate堅持IList <DayOfWeek>
- 23. 的IList <mutable_struct> VS mutable_struct []
- 24. AutoMapper與IList的<Item>
- 25. IList <T> to IQueryable <T>
- 26. Automapper映射IList <>到Iesi.Collections.Generic.ISet <>
- 27. 如何轉換爲IList類型?
- 28. 初始化IList <T> C#
- 29. 如何序列化IList <T>?
- 30. 如何分類IList <Class>?
既然你預先知道尺寸,你應該通過指定其初始大小創建新的列表,以避免調整:'新名單