LINQ statement value to ForEach C# WPF MVVM

本文关键字:WPF MVVM ForEach to statement value LINQ | 更新日期: 2023-09-27 18:33:20

SelectedStationCustomers
              .SelectMany(customer => String.Format("{0}", customer.CustomerTelephone))
              .ToList()
              .ForEach(customer => client.SendMessage("12345678", NEED VALUE HERE, textMessage));

如何从客户那里获得价值。客户电话,进入ForEach语句?我已经与客户尝试过。ToString(),但这似乎不起作用。

LINQ statement value to ForEach C# WPF MVVM

在这种情况下,

您不想使用SelectMany。 只需使用Select.

在您的示例中,String.Format对您没有任何作用。

SelectedStationCustomers
    .Select(customer => customer.CustomerTelephone)
    .ToList()
    .ForEach(customerTelephone => client.SendMessage("12345678", customerTelephone, textMessage));

我会使用Select而不是SelectMany:

SelectedStationCustomers
              .Select(customer => String.Format("{0}", customer.CustomerTelephone))
              .ToList()
              .ForEach(customer => client.SendMessage("12345678", customer, textMessage));

客户

将持有客户电话值