I have a method that should return a collection of anonymous objects:
/*Aqui deveria ser o tipo anonimo "AnonymousType"*/
[AnonymousType] ListarAnonimo()
{
//Especifica um "template" para o tipo retornado.
var lista = new[]
{
new
{
Nome = "",
Idade = 0,
Salario = 0.0m
}
}.ToList();
lista.Clear();
//Adiciona um item.
lista.Add(new
{
Nome = "Gato",
Idade = 25,
Salario = 3000000.0m
});
return lista;
}
I tried to get it to return a list of type List<dynamic>
but in this way I received the following compilation error:
Error CS0029 Can not implicitly convert type 'System.Collections.Generic.List < >' to 'System.Collections.Generic.List'
So I tried to use List<object>
but I got the same error.
Question
I'd like to know how I can return an anonymous type AnonymousType through a method?