Advertisement
butoff

T01_Interfaces

Mar 1st, 2018
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.73 KB | None | 0 0
  1. // Problem 1. Define an Interface IPerson
  2.  
  3. using System;
  4.  
  5. public class StartUp
  6. {
  7.     static void Main()
  8.     {
  9.         string name = Console.ReadLine();
  10.         int age = int.Parse(Console.ReadLine());
  11.  
  12.         IPerson person = new Citizen(name, age);
  13.         Console.WriteLine(person.Name);
  14.         Console.WriteLine(person.Age);
  15.     }
  16. }
  17.  
  18. public class Citizen : IPerson
  19. {
  20.     private string name;
  21.     private int age;
  22.  
  23.     public Citizen(string name, int age)
  24.     {
  25.         Name = name;
  26.         Age = age;
  27.     }
  28.  
  29.     public string Name { get => name; set => name = value; }
  30.     public int Age { get => age; set => age = value; }
  31. }
  32.  
  33. public interface IPerson
  34. {
  35.     string Name { get; set; }
  36.     int Age { get; set; }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement