Перегрузка индексаторов (Cannot implicitly convert type 'string' to 'int') - C#
Формулировка задачи:
Здрасте, есть код
Почему эти ошибки выскакивают, ведь я перегрузил индексаторы. Може кто-то объяснит мне?
Листинг программы
- if (cars[InputData.vendor] != null) //Cannot implicitly convert type 'string' to 'int'
- return cars[InputData.vendor]; //Cannot implicitly convert type 'string' to 'int'
- ....
- public CarClass this[int index]
- {
- get
- {
- for (int i = 0; i < CurrAuto; i++)
- if (i == index)
- return cars[i];
- return null;
- }
- }
- private int FindCar(string vendor)
- {
- for (int i = 0; i < CurrAuto; i++)
- if (cars[i].vendor == vendor)
- return i;
- return -1;
- }
- public CarClass this[string vendor]
- {
- get
- {
- if(vendor.Length != 0)
- return cars[this.FindCar(vendor)];
- return null;
- }
- }
Решение задачи: «Перегрузка индексаторов (Cannot implicitly convert type 'string' to 'int')»
textual
Листинг программы
- class CarClass
- {
- public RegistrationDateClass RegistrationDate = new RegistrationDateClass();
- public string vendor;
- public int IssueYear;
- public string color;
- public string number;
- public void PintCar()
- {
- Console.WriteLine("Registration date: {0}/{1}/{2}", RegistrationDate.day, RegistrationDate.month, RegistrationDate.year);
- Console.WriteLine("Vendor: {0}", vendor);
- Console.WriteLine("Issue year: {0}", IssueYear);
- Console.WriteLine("Color: {0}", color);
- Console.WriteLine("Number: {0}", number);
- }
- }
ИИ поможет Вам:
- решить любую задачу по программированию
- объяснить код
- расставить комментарии в коде
- и т.д