【发布时间】:2018-12-28 15:06:00
【问题描述】:
我有一个 Windows 应用程序,它有一些类似的代码,如下所示。
作为名为@987654321@的类。
class Order{
public string Orderid { get; set; }
public string CustName { get; set; }
}
现在,在此应用程序的另一个类中,创建了 Order 类的对象并为其分配了值。
Order order = new Order();
order = JObject.Parse(some JSON data).ToObject<Order>();
现在我想根据来自order 的Orderid 提取CustName。为此,我使用了 LINQ。
string custName = order.Where(s => s.Key == "o123").First().Value;
我正在使用 Sonarqube 来检查代码质量。当我运行 SonarQube 工具时,它表明我需要在使用 LINQ 的地方重构我的代码。这是它显示的确切线。
Drop 'Where' and move the condition into the 'First'.
我已经搜索了很多,但无法理解它想说什么。谁能解释我如何重构这条线,使其通过 SonarQube 的期望。
任何意见都非常有帮助。谢谢。
【问题讨论】:
-
order.First(s => s.Key == "o123")