Advertisement
Guest User

Untitled

a guest
Aug 19th, 2019
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. static void Main(string[] args)
  2. {
  3. string[] names = {
  4. "Joergen",
  5. "Watersheep",
  6. "Klaus",
  7. "Herbert",
  8. "Heinrich",
  9. "Günther"
  10. };
  11.  
  12. People people = new People(names);
  13.  
  14. people.PrintAllNames();
  15. Console.WriteLine();
  16. people.KillAllPeople();
  17.  
  18. Console.ReadLine();
  19. }
  20.  
  21. class Person
  22. {
  23. private string _Name { get; set; }
  24. public bool IsDead { get; set; }
  25.  
  26. public Person(string name)
  27. {
  28. this._Name = name;
  29. this.IsDead = false;
  30. }
  31.  
  32. public string GetName()
  33. {
  34. return this._Name;
  35. }
  36.  
  37. public void Kill()
  38. {
  39. this.IsDead = true;
  40. Console.WriteLine($"{this._Name} was like a father to me...");
  41. }
  42. }
  43.  
  44. class People
  45. {
  46. private List<Person> _People { get; set; }
  47.  
  48. public People(string[] names)
  49. {
  50. this._People = new List<Person>();
  51.  
  52. foreach (string name in names)
  53. {
  54. this._People.Add(new Person(name));
  55. }
  56. }
  57.  
  58. public void PrintAllNames()
  59. {
  60. foreach (Person person in _People)
  61. {
  62. Console.WriteLine(person.GetName());
  63. }
  64. }
  65.  
  66. public void KillAllPeople()
  67. {
  68. foreach (Person person in _People)
  69. {
  70. person.Kill();
  71. }
  72. }
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement