I wish to do something like the following in my data layer
public IEnumerable<{string,int}> ListIngredients()
{
return from i in RecipeIngredients select new {i.Ingredient.Name, i.Quantity};
}
this obviously doesnt work.
c# will only let me return IEnumerable and i wish to expose the structure.
You can’t do this using anonymous types. What you’re after is the
Tupletype from .NET 4.0 – you’d write:You can fairly easily create your own equivalent of course, if you can’t use .NET 4.0.