Advertisement
dmitryEfremov

Untitled

Jun 25th, 2025 (edited)
534
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.90 KB | None | 0 0
  1. using System;
  2.  
  3. namespace ConsoleApp1
  4. {
  5.     internal class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             //1
  10.             Console.WriteLine(1);
  11.             var person = new Person("Дима", "Ефремов", 22);
  12.             var p1 = person;
  13.             var p2 = person;
  14.             Console.WriteLine(p1);
  15.             Console.WriteLine(p2);
  16.             Mhetod(p1);
  17.             Console.WriteLine(p1);
  18.             Console.WriteLine(p2);
  19.             Mhetod2(ref p1);
  20.             Console.WriteLine(p1);
  21.             Console.WriteLine(p2);
  22.             //2
  23.             Console.WriteLine(2);
  24.             Mhetod3(out Person person3);
  25.             Console.WriteLine(person3);
  26.             //3-
  27.  
  28.             //4
  29.             Console.WriteLine(4);
  30.             Mhetod5(1, 2);
  31.             Mhetod5(1, 2, 3, 4);
  32.             Mhetod5(1, 2, d: 10);
  33.             Mhetod5(1, 2, d: 10, c: 15);
  34.  
  35.             //6
  36.             Console.WriteLine(6);
  37.             string userType = UserType.Friend.ToString();
  38.             Console.WriteLine(userType);
  39.             Console.WriteLine((byte)Mhetod6(userType));
  40.  
  41.             //8
  42.             Console.WriteLine(8);
  43.             UserType userTypes = UserType.Friend | UserType.Admin | UserType.Owner;
  44.  
  45.             //9
  46.             Console.WriteLine(9);
  47.             Mhetod9(userTypes, UserType.Annonim);
  48.             //10
  49.             Console.WriteLine(10);
  50.             var personn = new Personn("a", "b", 15, null);
  51.             Personn a = personn;
  52.             Personn b = personn;
  53.             Console.WriteLine(a);
  54.             Console.WriteLine(b);
  55.             a.Age = 10;
  56.             Console.WriteLine(a);
  57.             Console.WriteLine(b);
  58.             //11
  59.             Console.WriteLine(11);
  60.             Mhetod11(a);
  61.             Console.WriteLine(a);
  62.             //12
  63.             var person12 = new Personn("a", "b", 15, new Person("Dima", "Drim3", 10));
  64.             Console.WriteLine(12);
  65.             var pDeepCopy = person12.DeepCopy();
  66.             Console.WriteLine(pDeepCopy);
  67.             var pCopy = person12.Copy();
  68.             Console.WriteLine(pCopy);
  69.  
  70.             person12.Person.Age = 15;
  71.             Console.WriteLine("deep:" + pDeepCopy);
  72.             Console.WriteLine("copy" + pCopy);
  73.         }
  74.         //1
  75.         static void Mhetod(Person person)
  76.         {
  77.             person.FirstName = "1";
  78.         }
  79.         //1
  80.         static void Mhetod2(ref Person person)
  81.         {
  82.             person = new Person("2", person.LastName, person.Age);
  83.         }
  84.         //2
  85.         static void Mhetod3(out Person person)
  86.         {
  87.             person = new Person("Данил", "Данилов", 15);
  88.         }
  89.         //4
  90.         static void Mhetod5(int a, int b, int c = 5, int d = 6)
  91.         {
  92.             Console.WriteLine($"{a} {b} {c} {d}");
  93.         }
  94.         //6
  95.         static UserType Mhetod6(string userType)
  96.         {
  97.             return (UserType)Enum.Parse(typeof(UserType), userType);
  98.         }
  99.  
  100.         //9
  101.         static void Mhetod9(UserType userType, UserType check)
  102.         {
  103.             Console.WriteLine($"{check}? {(userType | check) == check}");
  104.         }
  105.         //11
  106.         static void Mhetod11(Personn personn)
  107.         {
  108.             personn.Age = 10111;
  109.         }
  110.  
  111.     }
  112.     //7
  113.     [Flags]
  114.     //5
  115.     public enum UserType : byte
  116.     {
  117.         Owner = 1,
  118.         Admin = 2,
  119.         Friend = 3,
  120.         Annonim = 4,
  121.     }
  122.  
  123.     public class Person
  124.     {
  125.         public string FirstName;
  126.         public string LastName;
  127.         public int Age;
  128.  
  129.         public Person(string firstName, string lastName, int age)
  130.         {
  131.             FirstName = firstName;
  132.             LastName = lastName;
  133.             Age = age;
  134.         }
  135.  
  136.         public override string ToString()
  137.         {
  138.             return "FirstName:" + FirstName + "\n" +
  139.                 "LastName:" + LastName + "\n" +
  140.                 "Age:" + Age + "\n";
  141.         }
  142.     }
  143.  
  144.  
  145.     public struct Personn
  146.     {
  147.         public string FirstName;
  148.         public string LastName;
  149.         public int Age;
  150.         public Person Person;
  151.  
  152.         public Personn(string firstName, string lastName, int age, Person person)
  153.         {
  154.             FirstName = firstName;
  155.             LastName = lastName;
  156.             Age = age;
  157.             Person = person;
  158.         }
  159.  
  160.         public Personn Copy()
  161.         {
  162.             return (Personn)this.MemberwiseClone();
  163.         }
  164.         public Personn DeepCopy()
  165.         {
  166.             Person newPerson = new Person(Person.FirstName, Person.LastName, Person.Age);
  167.             return new Personn(FirstName, LastName, Age, newPerson);
  168.         }
  169.  
  170.         public override string ToString()
  171.         {
  172.             return "FirstName:" + FirstName + "\n" +
  173.                 "LastName:" + LastName + "\n" +
  174.                 "Age:" + Age + "\n" +
  175.                 "Person" + Person + "\n";
  176.         }
  177.     }
  178. }
  179.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement