Почему не видна реализация ICompareble? - C#

Узнай цену своей работы

Формулировка задачи:

Вопрос почему при сортировке первого списка студия не видит мой метод Icompareble и как это исправить?
Листинг программы
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Collections;
  7.  
  8. namespace ConsoleApplication19
  9. {
  10. class AirlinesProperties : IComparable<AirlinesProperties>
  11. {
  12. public int number { set; get; }
  13. public int arrivalTime { get; set; }
  14.  
  15. public AirlinesProperties() { }
  16. public AirlinesProperties(int number, int arrivalTime)
  17. {
  18. this.number = number;
  19. this.arrivalTime = arrivalTime;
  20. }
  21. public int CompareTo(AirlinesProperties obj)
  22. {
  23. if (this.arrivalTime > obj.arrivalTime)
  24. return 1;
  25. if (this.arrivalTime < obj.arrivalTime)
  26. return -1;
  27. else
  28. return 0;
  29. }
  30. public override string ToString()
  31. {
  32. return String.Format(" {1}\tnumber: {2:C}\tarrivalTime: {3}%",
  33. this.arrivalTime, this.number);
  34. }
  35. }
  36. class Program
  37. {
  38. enum FlightType
  39. {
  40. flights,
  41. }
  42. struct AirplanesProperties
  43. {
  44. public int number;
  45. public string city;
  46. public string airline;
  47. public int terminal;
  48. public int arrivalTime;
  49. public int shippingFlight;
  50. public int bgate;
  51.  
  52. static void Main(string[] args)
  53. {
  54. long a;
  55. Console.WriteLine(@"Please, type the number:
  56. 1. arrivalTime1
  57. 2. udalenie elementa massiva
  58. 3. Poisk po aviakompanii
  59. ");
  60. a = long.Parse(Console.ReadLine());
  61. switch (a)
  62. {
  63. case 1:
  64. Arrivaltime1();
  65. Console.WriteLine("");
  66. break;
  67.  
  68. case 2:
  69. Airline();
  70. Console.WriteLine("");
  71. break;
  72. case 3:
  73. gate();
  74. Console.WriteLine("");
  75. break;
  76. default:
  77. Console.WriteLine("Exit");
  78. break;
  79. }
  80. Console.WriteLine("Press any key");
  81. Console.ReadLine();
  82. }
  83.  
  84. #region ArrivalTime1
  85. private static void Arrivaltime1()
  86. {
  87. int x;
  88. int y;
  89. int z;
  90. int k;
  91.  
  92. Console.WriteLine("arrivalTime1");
  93. x = Convert.ToInt32(Console.ReadLine());
  94. Console.WriteLine("arrivalTime2");
  95. y = Convert.ToInt32(Console.ReadLine());
  96. Console.WriteLine("arrivalTime3");
  97. z = Convert.ToInt32(Console.ReadLine());
  98. Console.WriteLine("arrivalTime4");
  99. k = Convert.ToInt32(Console.ReadLine());
  100. List<AirplanesProperties> fligths = new List<AirplanesProperties>();
  101. fligths.Add(new AirplanesProperties { number = 1, arrivalTime = x, });
  102. fligths.Add(new AirplanesProperties { number = 2, arrivalTime = y, });
  103. fligths.Add(new AirplanesProperties { number = 3, arrivalTime = z, });
  104. fligths.Add(new AirplanesProperties { number = 4, arrivalTime = k, });
  105.  
  106. fligths.Sort();
  107. foreach (AirplanesProperties a in fligths)
  108. Console.WriteLine(a);
  109. }
  110. #endregion
  111. // udalenie elementa massiva
  112. #region Airline
  113. private static void Airline()
  114. {
  115. List<AirplanesProperties> fligth = new List<AirplanesProperties>();
  116. fligth.Add(new AirplanesProperties { number = 1, city = "kiyev", airline = "PAU", terminal = 1, arrivalTime = 0, shippingFlight = 0, bgate = 1 });
  117. fligth.Add(new AirplanesProperties { number = 2, city = "kiyev", airline = "PAU", terminal = 1, arrivalTime = 0, shippingFlight = 0, bgate = 1 });
  118. fligth.Add(new AirplanesProperties { number = 3, city = "Odessa", airline = "MAU", terminal = 3, arrivalTime = 0, shippingFlight = 0, bgate = 1 });
  119. fligth.Add(new AirplanesProperties { number = 4, city = "Odessa", airline = "MAU", terminal = 5, arrivalTime = 0, shippingFlight = 0, bgate = 1 });
  120. fligth.Add(new AirplanesProperties { number = 4, city = "Odessa", airline = "RAU", terminal = 5, arrivalTime = 0, shippingFlight = 0, bgate = 1 });
  121. fligth.Add(new AirplanesProperties { number = 5, city = "Odessa", airline = "RAU", terminal = 5, arrivalTime = 0, shippingFlight = 0, bgate = 1 });
  122. int n = Convert.ToInt32(Console.ReadLine());
  123. fligth = fligth.Where(x => x.number != n).ToList<AirplanesProperties>();
  124. foreach (AirplanesProperties x in fligth)
  125. {
  126. Console.WriteLine(x.airline + x.arrivalTime + x.bgate + x.city + x.number);
  127. }
  128. }
  129. #endregion
  130. //Poisk po aviakompanii
  131. #region gate
  132. private static void gate()
  133. {
  134. List<AirplanesProperties> fligth = new List<AirplanesProperties>();
  135. fligth.Add(new AirplanesProperties { number = 1, city = "kiyev", airline = "PAU", terminal = 1, arrivalTime = 0, shippingFlight = 0, bgate = 1 });
  136. fligth.Add(new AirplanesProperties { number = 1, city = "kiyev", airline = "PAU", terminal = 1, arrivalTime = 0, shippingFlight = 0, bgate = 1 });
  137. fligth.Add(new AirplanesProperties { number = 1, city = "Odessa", airline = "MAU", terminal = 3, arrivalTime = 0, shippingFlight = 0, bgate = 1 });
  138. fligth.Add(new AirplanesProperties { number = 1, city = "Odessa", airline = "MAU", terminal = 5, arrivalTime = 0, shippingFlight = 0, bgate = 1 });
  139. fligth.Add(new AirplanesProperties { number = 1, city = "Odessa", airline = "RAU", terminal = 5, arrivalTime = 0, shippingFlight = 0, bgate = 1 });
  140. fligth.Add(new AirplanesProperties { number = 1, city = "Odessa", airline = "MAU", terminal = 5, arrivalTime = 0, shippingFlight = 0, bgate = 1 });
  141. string z = Convert.ToString(Console.ReadLine());
  142. List<AirplanesProperties> result = fligth.Where(x => x.airline == z).ToList();
  143. foreach (AirplanesProperties x in result)
  144. {
  145. Console.WriteLine(x.airline + x.arrivalTime + x.bgate + x.city + x.number);
  146. }
  147.  
  148. }
  149. }
  150. #endregion
  151. }
  152. }

Решение задачи: «Почему не видна реализация ICompareble?»

textual
Листинг программы
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. class Program
  6. {
  7.     class AirplanesProperties : IComparable<AirplanesProperties>
  8.     {
  9.         public int Number { get; set; }
  10.         public int ArrivalTime { get; set; }
  11.         public string City { get; set; }
  12.         public string Airline { get; set; }
  13.         public int Terminal { get; set; }
  14.         public int ShippingFlight { get; set; }
  15.         public int Bgate { get; set; }
  16.  
  17.         public AirplanesProperties() { }
  18.         public AirplanesProperties(int number, int arrivalTime)
  19.         {
  20.             Number = number;
  21.             ArrivalTime = arrivalTime;
  22.         }
  23.  
  24.         public int CompareTo(AirplanesProperties obj)
  25.         {
  26.             if (ArrivalTime > obj.ArrivalTime)
  27.                 return 1;
  28.             else if (ArrivalTime < obj.ArrivalTime)
  29.                 return -1;
  30.  
  31.             return 0;
  32.         }
  33.  
  34.         public override string ToString()
  35.         {
  36.             return String.Format(" {1}\tnumber: {0:C}\tarrivalTime: ", ArrivalTime, Number);
  37.         }
  38.     }
  39.  
  40.     #region ArrivalTime1
  41.     private static void Arrivaltime1()
  42.     {
  43.         int x, y, z, k;
  44.         Console.WriteLine("arrivalTime1");
  45.         x = Convert.ToInt32(Console.ReadLine());
  46.         Console.WriteLine("arrivalTime2");
  47.         y = Convert.ToInt32(Console.ReadLine());
  48.         Console.WriteLine("arrivalTime3");
  49.         z = Convert.ToInt32(Console.ReadLine());
  50.         Console.WriteLine("arrivalTime4");
  51.         k = Convert.ToInt32(Console.ReadLine());
  52.  
  53.         List<AirplanesProperties> fligths = new List<AirplanesProperties>()
  54.             {
  55.                 new AirplanesProperties { Number = 1, ArrivalTime = x, },
  56.                 new AirplanesProperties { Number = 2, ArrivalTime = y, },
  57.                 new AirplanesProperties { Number = 3, ArrivalTime = z, },
  58.                 new AirplanesProperties { Number = 4, ArrivalTime = k, }
  59.             };
  60.         fligths.Sort();
  61.         foreach (var item in fligths)
  62.             Console.WriteLine(item);
  63.     }
  64.     #endregion
  65.  
  66.     #region Airline
  67.     private static void Airline()
  68.     {
  69.         List<AirplanesProperties> fligth = new List<AirplanesProperties>()
  70.         {
  71.             new AirplanesProperties { Number = 1, City = "kiyev", Airline = "PAU", Terminal = 1, ArrivalTime = 0, ShippingFlight = 0, Bgate = 1 },
  72.             new AirplanesProperties { Number = 2, City = "kiyev", Airline = "PAU", Terminal = 1, ArrivalTime = 0, ShippingFlight = 0, Bgate = 1 },
  73.             new AirplanesProperties { Number = 3, City = "Odessa", Airline = "MAU", Terminal = 3, ArrivalTime = 0, ShippingFlight = 0, Bgate = 1 },
  74.             new AirplanesProperties { Number = 4, City = "Odessa", Airline = "MAU", Terminal = 5, ArrivalTime = 0, ShippingFlight = 0, Bgate = 1 },
  75.             new AirplanesProperties { Number = 4, City = "Odessa", Airline = "RAU", Terminal = 5, ArrivalTime = 0, ShippingFlight = 0, Bgate = 1 },
  76.             new AirplanesProperties { Number = 5, City = "Odessa", Airline = "RAU", Terminal = 5, ArrivalTime = 0, ShippingFlight = 0, Bgate = 1 }
  77.         };
  78.         int n = Convert.ToInt32(Console.ReadLine());
  79.         var filterFlight = fligth.Where(x => x.Number != n);
  80.         foreach (var x in filterFlight)
  81.         {
  82.             Console.WriteLine(x.Airline + x.ArrivalTime + x.Bgate + x.City + x.Number);
  83.         }
  84.     }
  85.     #endregion
  86.  
  87.     #region gate
  88.     private static void gate()
  89.     {
  90.         List<AirplanesProperties> fligth = new List<AirplanesProperties>()
  91.         {
  92.             new AirplanesProperties { Number = 1, City = "kiyev", Airline = "PAU", Terminal = 1, ArrivalTime = 0, ShippingFlight = 0, Bgate = 1 },
  93.             new AirplanesProperties { Number = 1, City = "kiyev", Airline = "PAU", Terminal = 1, ArrivalTime = 0, ShippingFlight = 0, Bgate = 1 },
  94.             new AirplanesProperties { Number = 1, City = "Odessa", Airline = "MAU", Terminal = 3, ArrivalTime = 0, ShippingFlight = 0, Bgate = 1 },
  95.             new AirplanesProperties { Number = 1, City = "Odessa", Airline = "MAU", Terminal = 5, ArrivalTime = 0, ShippingFlight = 0, Bgate = 1 },
  96.             new AirplanesProperties { Number = 1, City = "Odessa", Airline = "RAU", Terminal = 5, ArrivalTime = 0, ShippingFlight = 0, Bgate = 1 },
  97.             new AirplanesProperties { Number = 1, City = "Odessa", Airline = "MAU", Terminal = 5, ArrivalTime = 0, ShippingFlight = 0, Bgate = 1 }
  98.         };
  99.         string z = Console.ReadLine();
  100.         var result = fligth.Where(x => x.Airline == z);
  101.         foreach (var x in result)
  102.         {
  103.             Console.WriteLine(x.Airline + x.ArrivalTime + x.Bgate + x.City + x.Number);
  104.         }
  105.     }
  106.     #endregion
  107.  
  108.     static void Main()
  109.     {
  110.         Console.WriteLine(@"Please,  type the number:
  111.            1. arrivalTime1
  112.            2. udalenie elementa massiva
  113.            3. Poisk po aviakompanii
  114.            ");
  115.         int a = int.Parse(Console.ReadLine());
  116.         switch (a)
  117.         {
  118.             case 1:
  119.                 Arrivaltime1();
  120.                 Console.WriteLine("");
  121.                 break;
  122.             case 2:
  123.  
  124.                 Airline();
  125.                 Console.WriteLine("");
  126.                 break;
  127.             case 3:
  128.                 gate();
  129.                 Console.WriteLine("");
  130.                 break;
  131.             default:
  132.                 Console.WriteLine("Exit");
  133.                 break;
  134.         }
  135.         Console.ReadKey();
  136.     }
  137. }

ИИ поможет Вам:


  • решить любую задачу по программированию
  • объяснить код
  • расставить комментарии в коде
  • и т.д
Попробуйте бесплатно

Оцени полезность:

15   голосов , оценка 4.733 из 5

Нужна аналогичная работа?

Оформи быстрый заказ и узнай стоимость

Бесплатно
Оформите заказ и авторы начнут откликаться уже через 10 минут