1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
| public class Person
{
public string Firstname { get; set; }
public string Lastname { get; set; }
public int Age { get; set; }
}
public class Program_list
{
public List<Person> Person { get; set; } = new List<Person>();
public void List_method()
{
Person data = new Person();
Person[0].Firstname = "Prénom1";
Person[0].Lastname = "Nom1";
Person[0].Age = 30;
Person[1].Firstname = "Prénom2";
Person[1].Lastname = "Nom2";
Person[1].Age = 26;
Person[2].Firstname = "Prénom3";
Person[2].Lastname = "Nom3";
Person[2].Age = 26;
Person.Add(data);
}
public List<Person> GetList()
{
return Person;
}
}
public class Program_class
{
public void Main_method()
{
Program_list progList = new Program_list();
progList.List_method();
var person = progList.Person;
foreach (var i in person)
{
Console.WriteLine(i);
}
}
} |
Partager