EmiL EmiL - 1 year ago 65
ASP.NET (C#) Question

Adding a property to a list c# that doesn't contain it

I have a method that returns a

of datatype
. This class
only has 4 properties which I can return with this method.

Within my diagram
is a class that only is instanced within

I want to add a property to the new
I´m creating, for example I want to add the name of the

public List<Reserva> reservasNoPagas()
List<Reserva> reservasNoPagas = new List<Reserva>();

foreach (Espectaculo e in espectaculos)

//somewhere here I want to add e.name to the reservasNoPagas

return reservasNoPagas;

Answer Source

You can't add properties dynamically to classes. Inherit the class and add another in a new class:

public class ReservaExtended : Reserva
    public string ExtraProperty { get; set; }
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download