Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- namespace _DefiningClasses
- {
- public class Program
- {
- static void Main(string[] args)
- {
- List<Person> persons = new List<Person>();
- Person person1 = new Person();
- person1.Name = "Pesho";
- person1.Age = 20;
- Person person2 = new Person("Gosho", 18);
- Person person3 = new Person() { Name = "Stamat" };
- person3.Age = 43;
- persons.Add(person1);
- persons.Add(person2);
- persons.Add(person3);
- foreach (var person in persons)
- {
- Console.WriteLine($"{person.Name} {person.Age}");
- }
- }
- }
- public class Person
- {
- private string name;
- private int age;
- public string Name
- {
- get { return name; }
- set { name = value; }
- }
- public int Age
- {
- get { return age; }
- set { age = value; }
- }
- public Person()
- {
- }
- public Person(string name, int age)
- {
- this.name = name;
- this.age = age;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement