I try to instantiate several objects of the class Persona
, which has three attributes, what should be the correct syntax to be able to instantiate it directly in the constructor of the list of people?
// clase persona
public class persona
{
public string Nombre{ get; set; }
public string Apellidos{ get; set; }
public int Edad { get; set; }
}
// lista
List<persona> lista = new List<persona>();
I would like to be able to create them within the constructor itself although I have tried with the method Add()
and I have not known how to do it, how do you tell the Add () method what attribute do you want to write?
I guess it would be a complete rookie question, but I've been trying for a while and I have not managed to do it correctly.