Advertisement
Guest User

Untitled

a guest
Sep 20th, 2019
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. using System;
  2. namespace ConsoleApplication27
  3. {
  4. class Person
  5. {
  6. public string name;
  7. public int age;
  8.  
  9. public Person():this( "неизвестно")
  10. {
  11. }
  12. public Person(string name):this(name,18)
  13. {
  14. }
  15. public Person(string name, int age)
  16. {
  17. this.name=name;
  18. this.age=age;
  19. }
  20. public void GetInfo()
  21. {
  22. Console.WriteLine("Имя: {0} Возраст: {1}", name, age);
  23. }
  24. }
  25. class Program
  26. {
  27. static void Main(string[] args)
  28. {
  29. Person tom = new Person();//вызов первого конструктора
  30. Person bob = new Person("bob");//вызов второго конструктора
  31. Person sam = new Person("sam", 25);//вызов третьего конструктора
  32. tom.GetInfo();
  33. bob.GetInfo();
  34. sam.GetInfo();
  35. Console.ReadKey();
  36.  
  37. }
  38. }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement