I have a windows application which has some similar code as below.
As class named Order.
class Order{ public string Orderid { get; set; } public string CustName { get; set; } } Now, in another class in this application, object for Order class is created and value is assigned to it.
Order order = new Order(); order = JObject.Parse(some JSON data).ToObject<Order>(); Now I want to extract the CustName based on Orderid from order. For this I have used LINQ.
string custName = order.Where(s => s.Key == "o123").First().Value; I'm using Sonarqube to check the code quality. When I run the SonarQube tool , it is showing that I need to refactor my code where I have used LINQ. This is the exact line it shows.
Drop 'Where' and move the condition into the 'First'. I have searched for it a lot but couldn't understand what it is trying to say. Can anyone explain me how to refactor this line , so that it passes the SonarQube expectations.
Any input is highly helpful.Thanks.
order.First(s => s.Key == "o123")