Почему не видна реализация ICompareble? - C#
Формулировка задачи:
Вопрос почему при сортировке первого списка студия не видит мой метод Icompareble и как это исправить?
Листинг программы
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Collections;
- namespace ConsoleApplication19
- {
- class AirlinesProperties : IComparable<AirlinesProperties>
- {
- public int number { set; get; }
- public int arrivalTime { get; set; }
- public AirlinesProperties() { }
- public AirlinesProperties(int number, int arrivalTime)
- {
- this.number = number;
- this.arrivalTime = arrivalTime;
- }
- public int CompareTo(AirlinesProperties obj)
- {
- if (this.arrivalTime > obj.arrivalTime)
- return 1;
- if (this.arrivalTime < obj.arrivalTime)
- return -1;
- else
- return 0;
- }
- public override string ToString()
- {
- return String.Format(" {1}\tnumber: {2:C}\tarrivalTime: {3}%",
- this.arrivalTime, this.number);
- }
- }
- class Program
- {
- enum FlightType
- {
- flights,
- }
- struct AirplanesProperties
- {
- public int number;
- public string city;
- public string airline;
- public int terminal;
- public int arrivalTime;
- public int shippingFlight;
- public int bgate;
- static void Main(string[] args)
- {
- long a;
- Console.WriteLine(@"Please, type the number:
- 1. arrivalTime1
- 2. udalenie elementa massiva
- 3. Poisk po aviakompanii
- ");
- a = long.Parse(Console.ReadLine());
- switch (a)
- {
- case 1:
- Arrivaltime1();
- Console.WriteLine("");
- break;
- case 2:
- Airline();
- Console.WriteLine("");
- break;
- case 3:
- gate();
- Console.WriteLine("");
- break;
- default:
- Console.WriteLine("Exit");
- break;
- }
- Console.WriteLine("Press any key");
- Console.ReadLine();
- }
- #region ArrivalTime1
- private static void Arrivaltime1()
- {
- int x;
- int y;
- int z;
- int k;
- Console.WriteLine("arrivalTime1");
- x = Convert.ToInt32(Console.ReadLine());
- Console.WriteLine("arrivalTime2");
- y = Convert.ToInt32(Console.ReadLine());
- Console.WriteLine("arrivalTime3");
- z = Convert.ToInt32(Console.ReadLine());
- Console.WriteLine("arrivalTime4");
- k = Convert.ToInt32(Console.ReadLine());
- List<AirplanesProperties> fligths = new List<AirplanesProperties>();
- fligths.Add(new AirplanesProperties { number = 1, arrivalTime = x, });
- fligths.Add(new AirplanesProperties { number = 2, arrivalTime = y, });
- fligths.Add(new AirplanesProperties { number = 3, arrivalTime = z, });
- fligths.Add(new AirplanesProperties { number = 4, arrivalTime = k, });
- fligths.Sort();
- foreach (AirplanesProperties a in fligths)
- Console.WriteLine(a);
- }
- #endregion
- // udalenie elementa massiva
- #region Airline
- private static void Airline()
- {
- List<AirplanesProperties> fligth = new List<AirplanesProperties>();
- fligth.Add(new AirplanesProperties { number = 1, city = "kiyev", airline = "PAU", terminal = 1, arrivalTime = 0, shippingFlight = 0, bgate = 1 });
- fligth.Add(new AirplanesProperties { number = 2, city = "kiyev", airline = "PAU", terminal = 1, arrivalTime = 0, shippingFlight = 0, bgate = 1 });
- fligth.Add(new AirplanesProperties { number = 3, city = "Odessa", airline = "MAU", terminal = 3, arrivalTime = 0, shippingFlight = 0, bgate = 1 });
- fligth.Add(new AirplanesProperties { number = 4, city = "Odessa", airline = "MAU", terminal = 5, arrivalTime = 0, shippingFlight = 0, bgate = 1 });
- fligth.Add(new AirplanesProperties { number = 4, city = "Odessa", airline = "RAU", terminal = 5, arrivalTime = 0, shippingFlight = 0, bgate = 1 });
- fligth.Add(new AirplanesProperties { number = 5, city = "Odessa", airline = "RAU", terminal = 5, arrivalTime = 0, shippingFlight = 0, bgate = 1 });
- int n = Convert.ToInt32(Console.ReadLine());
- fligth = fligth.Where(x => x.number != n).ToList<AirplanesProperties>();
- foreach (AirplanesProperties x in fligth)
- {
- Console.WriteLine(x.airline + x.arrivalTime + x.bgate + x.city + x.number);
- }
- }
- #endregion
- //Poisk po aviakompanii
- #region gate
- private static void gate()
- {
- List<AirplanesProperties> fligth = new List<AirplanesProperties>();
- fligth.Add(new AirplanesProperties { number = 1, city = "kiyev", airline = "PAU", terminal = 1, arrivalTime = 0, shippingFlight = 0, bgate = 1 });
- fligth.Add(new AirplanesProperties { number = 1, city = "kiyev", airline = "PAU", terminal = 1, arrivalTime = 0, shippingFlight = 0, bgate = 1 });
- fligth.Add(new AirplanesProperties { number = 1, city = "Odessa", airline = "MAU", terminal = 3, arrivalTime = 0, shippingFlight = 0, bgate = 1 });
- fligth.Add(new AirplanesProperties { number = 1, city = "Odessa", airline = "MAU", terminal = 5, arrivalTime = 0, shippingFlight = 0, bgate = 1 });
- fligth.Add(new AirplanesProperties { number = 1, city = "Odessa", airline = "RAU", terminal = 5, arrivalTime = 0, shippingFlight = 0, bgate = 1 });
- fligth.Add(new AirplanesProperties { number = 1, city = "Odessa", airline = "MAU", terminal = 5, arrivalTime = 0, shippingFlight = 0, bgate = 1 });
- string z = Convert.ToString(Console.ReadLine());
- List<AirplanesProperties> result = fligth.Where(x => x.airline == z).ToList();
- foreach (AirplanesProperties x in result)
- {
- Console.WriteLine(x.airline + x.arrivalTime + x.bgate + x.city + x.number);
- }
- }
- }
- #endregion
- }
- }
Решение задачи: «Почему не видна реализация ICompareble?»
textual
Листинг программы
- using System;
- using System.Collections.Generic;
- using System.Linq;
- class Program
- {
- class AirplanesProperties : IComparable<AirplanesProperties>
- {
- public int Number { get; set; }
- public int ArrivalTime { get; set; }
- public string City { get; set; }
- public string Airline { get; set; }
- public int Terminal { get; set; }
- public int ShippingFlight { get; set; }
- public int Bgate { get; set; }
- public AirplanesProperties() { }
- public AirplanesProperties(int number, int arrivalTime)
- {
- Number = number;
- ArrivalTime = arrivalTime;
- }
- public int CompareTo(AirplanesProperties obj)
- {
- if (ArrivalTime > obj.ArrivalTime)
- return 1;
- else if (ArrivalTime < obj.ArrivalTime)
- return -1;
- return 0;
- }
- public override string ToString()
- {
- return String.Format(" {1}\tnumber: {0:C}\tarrivalTime: ", ArrivalTime, Number);
- }
- }
- #region ArrivalTime1
- private static void Arrivaltime1()
- {
- int x, y, z, k;
- Console.WriteLine("arrivalTime1");
- x = Convert.ToInt32(Console.ReadLine());
- Console.WriteLine("arrivalTime2");
- y = Convert.ToInt32(Console.ReadLine());
- Console.WriteLine("arrivalTime3");
- z = Convert.ToInt32(Console.ReadLine());
- Console.WriteLine("arrivalTime4");
- k = Convert.ToInt32(Console.ReadLine());
- List<AirplanesProperties> fligths = new List<AirplanesProperties>()
- {
- new AirplanesProperties { Number = 1, ArrivalTime = x, },
- new AirplanesProperties { Number = 2, ArrivalTime = y, },
- new AirplanesProperties { Number = 3, ArrivalTime = z, },
- new AirplanesProperties { Number = 4, ArrivalTime = k, }
- };
- fligths.Sort();
- foreach (var item in fligths)
- Console.WriteLine(item);
- }
- #endregion
- #region Airline
- private static void Airline()
- {
- List<AirplanesProperties> fligth = new List<AirplanesProperties>()
- {
- new AirplanesProperties { Number = 1, City = "kiyev", Airline = "PAU", Terminal = 1, ArrivalTime = 0, ShippingFlight = 0, Bgate = 1 },
- new AirplanesProperties { Number = 2, City = "kiyev", Airline = "PAU", Terminal = 1, ArrivalTime = 0, ShippingFlight = 0, Bgate = 1 },
- new AirplanesProperties { Number = 3, City = "Odessa", Airline = "MAU", Terminal = 3, ArrivalTime = 0, ShippingFlight = 0, Bgate = 1 },
- new AirplanesProperties { Number = 4, City = "Odessa", Airline = "MAU", Terminal = 5, ArrivalTime = 0, ShippingFlight = 0, Bgate = 1 },
- new AirplanesProperties { Number = 4, City = "Odessa", Airline = "RAU", Terminal = 5, ArrivalTime = 0, ShippingFlight = 0, Bgate = 1 },
- new AirplanesProperties { Number = 5, City = "Odessa", Airline = "RAU", Terminal = 5, ArrivalTime = 0, ShippingFlight = 0, Bgate = 1 }
- };
- int n = Convert.ToInt32(Console.ReadLine());
- var filterFlight = fligth.Where(x => x.Number != n);
- foreach (var x in filterFlight)
- {
- Console.WriteLine(x.Airline + x.ArrivalTime + x.Bgate + x.City + x.Number);
- }
- }
- #endregion
- #region gate
- private static void gate()
- {
- List<AirplanesProperties> fligth = new List<AirplanesProperties>()
- {
- new AirplanesProperties { Number = 1, City = "kiyev", Airline = "PAU", Terminal = 1, ArrivalTime = 0, ShippingFlight = 0, Bgate = 1 },
- new AirplanesProperties { Number = 1, City = "kiyev", Airline = "PAU", Terminal = 1, ArrivalTime = 0, ShippingFlight = 0, Bgate = 1 },
- new AirplanesProperties { Number = 1, City = "Odessa", Airline = "MAU", Terminal = 3, ArrivalTime = 0, ShippingFlight = 0, Bgate = 1 },
- new AirplanesProperties { Number = 1, City = "Odessa", Airline = "MAU", Terminal = 5, ArrivalTime = 0, ShippingFlight = 0, Bgate = 1 },
- new AirplanesProperties { Number = 1, City = "Odessa", Airline = "RAU", Terminal = 5, ArrivalTime = 0, ShippingFlight = 0, Bgate = 1 },
- new AirplanesProperties { Number = 1, City = "Odessa", Airline = "MAU", Terminal = 5, ArrivalTime = 0, ShippingFlight = 0, Bgate = 1 }
- };
- string z = Console.ReadLine();
- var result = fligth.Where(x => x.Airline == z);
- foreach (var x in result)
- {
- Console.WriteLine(x.Airline + x.ArrivalTime + x.Bgate + x.City + x.Number);
- }
- }
- #endregion
- static void Main()
- {
- Console.WriteLine(@"Please, type the number:
- 1. arrivalTime1
- 2. udalenie elementa massiva
- 3. Poisk po aviakompanii
- ");
- int a = int.Parse(Console.ReadLine());
- switch (a)
- {
- case 1:
- Arrivaltime1();
- Console.WriteLine("");
- break;
- case 2:
- Airline();
- Console.WriteLine("");
- break;
- case 3:
- gate();
- Console.WriteLine("");
- break;
- default:
- Console.WriteLine("Exit");
- break;
- }
- Console.ReadKey();
- }
- }
ИИ поможет Вам:
- решить любую задачу по программированию
- объяснить код
- расставить комментарии в коде
- и т.д