У меня есть список C # IE List<Food> x = new List<Food> () ;
Этот список заполнен этим классом
public class Food {
public string id { get; set; }
public string idUser { get; set; }
public string idType { get; set; }
//idType could be Fruit , Meat , Vegetable , Candy
public string location { get; set; }
}
Теперь у меня есть несортированный List<Food> list ;
, который имеетIE 15 элементов.Есть 8 видов овощей, 3 вида фруктов, 1 вид мяса, 1 вид конфет
Я бы отсортировал это так, чтобы список упорядочился следующим образом:
1° : Food.idType Fruit
2° : Food.idType Vegetables
3° : Food.idType Meat
4° : Food.idType Candy
5° : Food.idType Fruit
6° : Food.idType Vegetables
7° : Food.idType Fruit //Becouse there isnt more Meat so i insert the
//next one which is Candy but also this type is empty
//so i start from begin : Fruit
8° : Food.idType Vegetables
9° : Food.idType Vegetables // For the same reason of 7°
10 ° Food.idType Vegetables
......
....
....
15 : Food.idType Vegetables
Я не могу найтиправило, чтобы сделать это.Существуют ли инструкции linq или List.Sort, которые помогают мне упорядочить список таким образом?
Обновление Я изменил возвращаемое значение idType и теперь возвращаю тип int вместо строки, поэтому 1 =Овощ, 2 = Фрукты, 3 = Конфеты 4 = Мясо