📌  相关文章
📜  list cast<> c# 代码示例

📅  最后修改于: 2022-03-11 14:49:06.841000             🧑  作者: Mango

代码示例3
There are many ways to do that, I think there are two you should consider:

You can use Cast and ToList, but it will require using System.Linq.

var listOfStrings = new List() { "foo", "bar" };
var listOfObjects = listOfStrings.Cast().ToList();

To avoid that, you can use new List(IEnumerable source) constructor. Because IEnumerable is covariant, you can do following:

var listOfStrings = new List() { "foo", "bar" };
var listOfObjects = new List(listOfString);