PramodChoudhari PramodChoudhari - 2 months ago 12
C# Question

assign value using linq

public class Company
public int id { get; set; }
public int Name { get; set; }

List<Company> listofCompany = new List<Company>();

this is my collection of company list I want to assign values to Name property using LINQ

listofCompany.Where(d => d.Id = 1);

(I want to assing name property of company id 1)

how do I assign it.?


using Linq would be:

 listOfCompany.Where(c=> == 1).FirstOrDefault().Name = "Whatever Name";


For multiple items (condition is met by multiple items):

 listOfCompany.Where(c=> == 1).ToList().ForEach(cc => cc.Name = "Whatever Name");