I have a List
of MyType1
objects. I want to copy all these objects in a new List
of MyType2
objects, having a constructor for MyType2
that takes a MyType1
object as argument.
我现在这样做:
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);
}
是否有办法实现这一一线(如果认为与林克有可能的话)?