I have a problem here..
I expect
List<IVehicle> objCars = new List<Car>();
to work just like
IVehicle objCar = new Car();
but it shows error.
What has gone wrong? Explanations would be greatly appreciated..
Thanks
Kiran
Code below for a Console Application
//--------------------------------------------------
using
System;
using
System.Collections.Generic;
using
System.Text;
namespace
Interface_in_List_Generic_Test
{
interface IVehicle
{
void Start();
void ApplyBreaks();
}
class Car : IVehicle
{
public void Start()
{
Console.WriteLine("Starting Car"); }
public void ApplyBreaks()
{ Console.WriteLine("Car Decelerating..."); }
}
class Program
{
static void Main(string[] args)
{
//Below Code Works....
IVehicle objCar = new Car();
objCar.ApplyBreaks();
//Below code shows error-> Cannot implicitly convert type...
List<IVehicle> objCars = new List<Car>();
}
}
}
/*Cannot implicitly convert type
'System.Collections.Generic.List<Interface_in_List_Generic_Test.Car>' to 'System.Collections.Generic.List<Interface_in_List_Generic_Test.IVehicle>' C:\KVR\KVR Devs\comboBoxSample\Interface in List Generic Test\Program.cs 33 38 Interface in List Generic Test*/