public class Item
{
public Item(string name, int id, double cost)
{
Name = name;
Id = id;
Cost = cost;
}
public string Name { get; set; }
public int Id { get; set; }
public double Cost { get; set; }
public override string ToString()
{
return $"Id: {Id}, Name: {Name}, Cost: {Cost}";
}
}
static void Main(string[] args)
{
var findName = "Ball";
var items = new List<Item>
{
new Item("Ball", 10, 3),
new Item("Toy", 14, 15)
};
var item = items.FirstOrDefault(product => product.Name.Contains(findName));
if (item != null)
{
item.Cost = 100;
item.Id = 999;
}
Console.WriteLine(string.Join(Environment.NewLine, items));
Console.ReadKey();