AlexRaynor

OOP 1 + 2;

Oct 27th, 2019
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.61 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace ConsoleApp23
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.  
  14.             Cat cat = new Cat("Tom", 10, 2, 0.6f);
  15.             cat.Age = 9;
  16.             cat.Weight = 7;
  17.             cat.Meow();
  18.  
  19.         }
  20.     }
  21.  
  22.     class Cat
  23.     {
  24.         public string Name = "Dosya";
  25.         public int age = 3;
  26.  
  27.         public int Height = 1;
  28.         public float tailLength = 0.3f;
  29.    
  30.  
  31.     public Cat()
  32.         {
  33.             Name = "Vasya";
  34.         }
  35.  
  36.         public Cat(string Name, int age, int Height, float tailLength)
  37.         {
  38.             this.Name = Name;
  39.             this.age = Age;
  40.             //this.Weight = Weight;
  41.             this.Height = Height;
  42.             this.tailLength = tailLength;
  43.         }
  44.  
  45.         public int Age
  46.         {
  47.             get { return age;  }
  48.             set { age = value; }
  49.         }
  50.  
  51.         public int Weight
  52.         {
  53.             get;
  54.             set;
  55.         }
  56.  
  57.  
  58.         public void Meow()
  59.         {
  60.             Console.WriteLine("Мое имя: "+ Name + ", мне " + age + " лет," + " рост: " + Height + " локоть, " + "вес: " + Weight + " кило, " + "длина хвоста: " + tailLength + " метра.");
  61.         }
  62.     }
  63.  
  64.     // Если переделать в struct, появляется ошибка о том, что в структуре не могут содержаться инициализаторы полей (переменных класса).
  65.  
  66.  
  67. }
Advertisement
Add Comment
Please, Sign In to add comment