Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/275.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 将对象数组添加到扩展对象列表的最佳方法_C# - Fatal编程技术网

C# 将对象数组添加到扩展对象列表的最佳方法

C# 将对象数组添加到扩展对象列表的最佳方法,c#,C#,我有一个名为“customerArray”的数组Customers[]和一个名为“extendedCustomerList”的通用列表List ExtendedCustomer类包含一些属性,其中一个是“Customer”(是的,与数组中的对象相同),如下所示: public class ExtendedCustomer { public Customer { get; set; } public OtherProperty { get; set; } .... }

我有一个名为“customerArray”的数组
Customers[]
和一个名为“extendedCustomerList”的通用列表
List

ExtendedCustomer
类包含一些属性,其中一个是“Customer”(是的,与数组中的对象相同),如下所示:

public class ExtendedCustomer {
     public Customer { get; set; }
     public OtherProperty { get; set; }
     ....
}
将客户阵列添加到ExtendedCustomers列表中的最快/最佳/最简单/性能最佳/最漂亮的方法是什么?ExtendedCustomer中的其他属性可以保留默认的空值

我不喜欢循环

可以用于从客户到扩展客户的投影:

extendedCustomerList.AddRange(customerArray.Select(
    c => new ExtendedCustomer() {
        Customer = c
    }));
您可以使用从客户到扩展客户的投影:

extendedCustomerList.AddRange(customerArray.Select(
    c => new ExtendedCustomer() {
        Customer = c
    }));
Customer[]客户=。。。;
列出扩展客户=。。。;
extendedCustomers.AddRange(
选择(c=>newextendedcustomer{Customer=c});
客户[]客户=。。。;
列出扩展客户=。。。;
extendedCustomers.AddRange(
选择(c=>newextendedcustomer{Customer=c});
使用LINQ:

extendedCustomerList.AddRange(
    from customer in customerArray
    select new ExtendedCustomer {
        Customer = customer
    }
);
使用LINQ:

extendedCustomerList.AddRange(
    from customer in customerArray
    select new ExtendedCustomer {
        Customer = customer
    }
);