Advertisement
stictt

C# структуры/ссылки

Dec 14th, 2020 (edited)
725
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.81 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Net;
  4. using System.Collections.Generic;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using Newtonsoft.Json;
  8. using System.Net.Http;
  9. using Newtonsoft.Json.Linq;
  10. using System.Threading;
  11. using System.IO;
  12. using System.Collections;
  13.  
  14. namespace УрокПотоки
  15. {
  16.  
  17.    
  18.     public interface IConsole
  19.     {
  20.          void print();
  21.     }
  22.    
  23.     struct testStruct : IConsole
  24.     {
  25.         public string value { get; set; }
  26.         public testStruct(string value) { this.value = value; }
  27.         public void print()
  28.         {
  29.             value = value + " каст";
  30.             Console.Write(value);
  31.         }
  32.     }
  33.     class testClass : IConsole
  34.     {
  35.         public string value { get; set; }
  36.         public testClass(string value) { this.value = value; }
  37.         public void print()
  38.         {
  39.             value = value + " каст";
  40.             Console.Write(value);
  41.         }
  42.     }
  43.  
  44.  
  45.  
  46.     class Example
  47.     {
  48.         static void Main()
  49.         {
  50.             testStruct tesStruct = new testStruct("base");
  51.             testClass tesClass = new testClass("base");
  52.             Console.WriteLine($"Класс без каста хранит [{tesClass.value}] || Структура без каста хранит[{ tesStruct.value}]");
  53.             Console.Write("Класс с кастом выдаст [");
  54.             ((IConsole)tesClass).print();
  55.             Console.Write("] \n");
  56.             Console.Write("Структура с кастом выдаст [");
  57.             ((IConsole)tesStruct).print();
  58.             Console.Write("] \n");
  59.             Console.WriteLine($"Класс после каста хранит [{tesClass.value}] || Структура после каста хранит[{ tesStruct.value}]");
  60.         }
  61.    
  62.     }
  63.  
  64. }
  65.  
  66.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement