Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- namespace testProgram
- {
- public class Program
- {
- public static void Main()
- {
- PersonModel jason = new PersonModel("Jason", "Young", 33);
- PersonModel joe = new PersonModel("Joe", "Smith", 44);
- PersonModel mark = new PersonModel("Mark", "Jones", 26);
- List<PersonModel> people = new List<PersonModel>();
- people.Add(jason);
- people.Add(joe);
- people.Add(mark);
- foreach(var person in people)
- person.DisplayPersonInfo();
- }
- }
- class PersonModel
- {
- private int Id {get; set;}
- public string FirstName {get; set;}
- public string LastName {get; set;}
- public int Age {get; set;}
- public PersonModel() {}
- public PersonModel (string firstName, string lastName, int age)
- {
- this.Id = GetId();
- this.FirstName = firstName;
- this.LastName = lastName;
- this.Age = age;
- }
- private static int personId = 1000;
- // Set unique Id for each created person
- private int GetId()
- {
- return ++personId;
- }
- public void DisplayPersonInfo()
- {
- Console.WriteLine("ID: {0} First Name: {1}, Last Name: {2}, Age: {3}", this.Id, this.FirstName, this.LastName, this.Age);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement