List Manipulation in C# using Linq
Posted
by Learner
on Stack Overflow
See other posts from Stack Overflow
or by Learner
Published on 2008-12-12T04:47:30Z
Indexed on
2010/05/20
16:00 UTC
Read the original article
Hit count: 358
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
namespace ConsoleApplication1
{
public class Class1
{
static void Main(string[] args)
{
List<Car> mylist = new List<Car>();
Car car1;
Car car2;
Car car3;
car1 = new Car()
{
make = "Honda",
id = 1
};
car2 = new Car()
{
make = "toyota",
id = 2
};
car3 = new Car()
{
make = "Honda",
id = 3,
color = "red"
};
mylist.Add(car1);
mylist.Add(car2);
**////mylist.Where(p => p.id == 1).SingleOrDefault() = car3;**
}
}
public class Car
{
public int id { get; set; }
public string make { get; set; }
public string color { get; set; }
}
}
How can I update the list by replacing the honda car of Id 1 with honda car with Id 3 in the best way.
© Stack Overflow or respective owner