Advertisement
kasper_k

7laboop

Oct 25th, 2022
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.85 KB | None | 0 0
  1. static void Main(string[] args)
  2.         {
  3.             Person User1 = new Person("Ilsaf", "Musin", new DateTime(2003, 05, 27));
  4.             Person User2 = new Person();
  5.             User2.Year = 1999;
  6.             Console.WriteLine("User1: {0}, {1}, {2}",User1.Name, User1.Surname, User1.DayOfBDay);
  7.             Console.WriteLine(User2.ToString());
  8.             Console.WriteLine(User2.ToShortString());
  9.         }
  10.  
  11.  
  12. using System;
  13. using System.Collections.Generic;
  14. using System.Text;
  15.  
  16. namespace lab66oop
  17. {
  18.     public class Person
  19.     {
  20.         private string name;
  21.         private string surname;
  22.         private DateTime dayofBDay;
  23.         public Person(string name, string surname, DateTime dayofBDay)
  24.         {
  25.             this.name = name;
  26.             this.surname = surname;
  27.             this.dayofBDay = dayofBDay;
  28.         }
  29.         public Person()
  30.         {
  31.             this.name = "NoName";
  32.             this.surname = "NoNamemov";
  33.             this.dayofBDay = new DateTime();
  34.         }
  35.         public string Name
  36.         {
  37.             get { return this.name; }
  38.             set { this.name = value; }
  39.         }
  40.         public string Surname
  41.         {
  42.             get { return this.surname; }
  43.             set { this.surname = value; }
  44.         }
  45.         public DateTime DayOfBDay
  46.         {
  47.             get { return this.dayofBDay; }
  48.             set { this.dayofBDay = value; }
  49.         }
  50.         public int Year
  51.         {
  52.             get { return this.dayofBDay.Year; }
  53.             set => this.dayofBDay = new DateTime(value, this.dayofBDay.Month, this.dayofBDay.Day);
  54.         }
  55.         public override string ToString()
  56.         {
  57.             return $"{this.name} {this.surname} {this.dayofBDay}";
  58.         }
  59.         public virtual string ToShortString()
  60.         {
  61.             return $"{this.name} {this.surname}";
  62.         }
  63.     }    
  64. }
  65.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement