Advertisement
Guest User

Untitled

a guest
Oct 17th, 2019
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.02 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. namespace OOP_3Laba
  5. {
  6.  
  7.     class MainClass
  8.     {
  9.         public static void Main()
  10.         {
  11.  
  12.             //Конструктор по умолчанию
  13.             Tree FirstTree = new Tree();
  14.             FirstTree.GetInfo();
  15.  
  16.             //Конструктор с параметрами
  17.             Tree SecondTree = new Tree("YoungOak", 14, 212);
  18.             SecondTree.GetInfo();
  19.  
  20.  
  21.             //Конструктор копирования
  22.             //Копируемый объект
  23.             Tree CopyMe = new Tree("CopyMe", 30, 300);
  24.             //Копируем объект
  25.             Tree CopyToMe = new Tree(CopyMe);
  26.  
  27.             //Get и Set
  28.             Tree Birch = new Tree("Birch", 30, 100);
  29.             //Устанавливаем через set
  30.             Birch.SetTreeAge = 1000;
  31.             //Обращение к get
  32.             Console.WriteLine(Birch.SetTreeAge);
  33.  
  34.             //Анонимный тип
  35.             var user = new { Name = "Tom", Age = 34 };
  36.             Console.WriteLine(user.Name);
  37.  
  38.  
  39.  
  40.             //Out
  41.             {
  42.                int perimetr;
  43.                int area;
  44.                GetAreaAndPerim(5, 4, out area, out perimetr);
  45.             }
  46.  
  47.             void GetAreaAndPerim(int x, int y, out int area, out int perimetr)
  48.             {
  49.                 area = x * y;
  50.                 perimetr = (x * y) / 2;
  51.             }
  52.  
  53.             Ref.AdditionVal(5, 5);
  54.  
  55.             //List
  56.             List<int> MyCollection = new List<int>();
  57.             MyCollection.Add(10);
  58.             MyCollection.Add(20);
  59.             MyCollection.Add(30);
  60.  
  61.  
  62.             //Вывести все элементы коллекции
  63.             void GetAllValuesOfCollection()
  64.             {
  65.                 foreach (int numbers in MyCollection)
  66.                 {
  67.                     Console.WriteLine(numbers);
  68.                 }
  69.             }
  70.  
  71.             GetAllValuesOfCollection();
  72.  
  73.  
  74.         }
  75.     }
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement