Lets say i have following class
public class abc
{
int id;
string name;
}
i am using this class as a collection of some data and my business logic appends some rows in it.
List<abc> lstData = GetData();
Now if i have to modify some property value lets say i want to modify the name property with some value.
string replaceName = 'jay';
so this jay should be in every row of the list in name property.
how to do this ? i think there is a convertAll method can we use that….
ConvertAllis usually used to create a new list, whereas it sounds like you just want to modify properties within existing objects. So I’d use:(This code would look more idiomatic if you’d used names following the .NET naming conventions, by the way.)
Alternatively, you could use
ConvertAllif you wanted to create new objects:That’s using a lambda expression for the delegate, and an object initializer to set the properties in each new object. The exact way that you’d approach this would depend on your real class.