将对象列表复制到一行代码中的另一个类型列表中

Oti*_*iel 3 c# linq coding-style

我有一个ListMyType1对象.我想在一个新ListMyType2对象中复制所有这些对象,有一个构造函数MyType2,它将一个MyType1对象作为参数.

现在,我这样做:

List<MyType1> type1objects = new List<MyType1>();
// Fill type1objects
// ...
List<MyType2> type2objects = new List<MyType2>();
foreach (MyType1 type1obj in type1objects) {
    MyType2 type2obj = new MyType2(type1obj);
    type2objects.Add(type2obj);
}
Run Code Online (Sandbox Code Playgroud)

有没有办法做到这一行(我想也许Linq可能)?

Ili*_*a G 7

var type2objects = type1objects.Select(o => new MyType2(o)).ToList();
Run Code Online (Sandbox Code Playgroud)