Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- using System.Net;
- using System.Collections.Generic;
- using System.Text;
- using System.Threading.Tasks;
- using Newtonsoft.Json;
- using System.Net.Http;
- using Newtonsoft.Json.Linq;
- using System.Threading;
- using System.IO;
- using System.Collections;
- namespace УрокПотоки
- {
- public interface IConsole
- {
- void print();
- }
- struct testStruct : IConsole
- {
- public string value { get; set; }
- public testStruct(string value) { this.value = value; }
- public void print()
- {
- value = value + " каст";
- Console.Write(value);
- }
- }
- class testClass : IConsole
- {
- public string value { get; set; }
- public testClass(string value) { this.value = value; }
- public void print()
- {
- value = value + " каст";
- Console.Write(value);
- }
- }
- class Example
- {
- static void Main()
- {
- testStruct tesStruct = new testStruct("base");
- testClass tesClass = new testClass("base");
- Console.WriteLine($"Класс без каста хранит [{tesClass.value}] || Структура без каста хранит[{ tesStruct.value}]");
- Console.Write("Класс с кастом выдаст [");
- ((IConsole)tesClass).print();
- Console.Write("] \n");
- Console.Write("Структура с кастом выдаст [");
- ((IConsole)tesStruct).print();
- Console.Write("] \n");
- Console.WriteLine($"Класс после каста хранит [{tesClass.value}] || Структура после каста хранит[{ tesStruct.value}]");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement