在以下代码段中需要帮助:
static void Main(string[] args)
{
var customers = new HashSet<Customer>();
var action = new Action(() =>
{
var innerCustomers = new Customer[]
{
new Customer { CustomerID = 1, CustomerName = "C 1" },
new Customer { CustomerID = 2, CustomerName = "C 2" },
};
innerCustomers.Select(c => customers.Add(c)); //doesn't work
foreach (var customer in innerCustomers)
customers.Add(customer); //works fine
});
action();
}
innerCustomers.Select(c => customers.Add(c));
在“客户”集合中插入记录方面似乎没有工作,但是,该行下方的“foreach”工作正常。有人知道为什么它不能在 linq 中工作吗?我知道我没有从 select 方法中选择任何东西