I'm trying to move from Ilist to list and then display it in a DataGridView but I get an error ... it tells me that it is not possible to implicitly convert
List<Empleado> lista = new List<Empleado>();
lista = servicio.Consultar();
I'm trying to move from Ilist to list and then display it in a DataGridView but I get an error ... it tells me that it is not possible to implicitly convert
List<Empleado> lista = new List<Empleado>();
lista = servicio.Consultar();
Good morning, The issue is that IList < > is an Interface, instead List < > is a class, IList exposes public methods that the List class implements. To solve your problem, you have three options, make the method return a List, or that the variable where you receive it is IList, or pass it the Interface in the constructor
IList<Empleado> lista;
lista = servicio.Consultar();
List<Empleado> lista = new List<Empleado>(servicio.Consultar());
Atte
Use the extender method ToList()
about the type IList<Empleado>
:
List<Empleado> empleados = servicio.Consultar().ToList();
IList<T>
implement IEnumerable<T>
so you have available all the extensor methods of System.Linq.Enumerable
, among them is the List<T> ToList(this IEnumerable<T> source)
method that converts a IEnumerable<T>
to List<T>
.
What you must do is have the new list created by passing to the constructor the IList
that your method returns servicio.Consultar()
:
List<Empleado> lista = new List<Empleado>(servicio.Consultar());