2
class Car{
int ID {get;set;}
string Text {get;set;}
}
List<Car> allCars = new List<Car>(){ new Car{ ID = 1, Text = "one"}, new Car{ ID = 2, Text = "two"}, new Car{ ID = 3, Text = "three"}, new Car{ ID = 4, Text = "four"} };
int[] existingCarIds = new int[]{ 2, 4 };
我想要這個列表。使用LINQ使用現有陣列排列列表
CarWithID2
CarWithID4
CarWithID1
CarWithID3
所以我做:
List<Car> carList = allCars.Where(d => existingCarIds.Contains(d.ID)).Concat(allCars.Where(d => !existingCarIds.Contains(d.ID))).ToList();
是否有任何其他的方式做同樣的查詢?
謝謝
洛倫佐。