Advertisement
VictoriaLodochkina

lab 6 z 11 csharp

Oct 20th, 2021
730
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.01 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 lab_6_csharp_z_1._1
  8. {
  9.     interface Ix
  10.     {
  11.         string F0(int n);
  12.         void F1(int n2);
  13.     }
  14.  
  15.     interface Iy
  16.     {
  17.         void F0(int n, out string s);
  18.         void F1(int n2);
  19.     }
  20.     public class Cl1: Ix, Iy
  21.     {
  22.         public string str1;
  23.         public Cl1() { }
  24.         public Cl1(string st)
  25.         {
  26.             this.str1 = st;
  27.         }
  28.         public string F0(int n)
  29.         {
  30.             //Console.WriteLine("From class 1, interface Ix");
  31.             string s1=string.Copy(str1);
  32.             string s2 = string.Copy(s1.Remove(n, 1));
  33.             s1 = "";
  34.             s1 = s2 + s2;
  35.             return s1;
  36.         }
  37.         public void F1(int n2)
  38.         {
  39.             //Console.WriteLine("From class 1, interface ???");
  40.             string s1 = string.Copy(str1);
  41.             string s2 = string.Copy(s1.Remove(n2, 1));
  42.             s1 = "";
  43.             s1 = s2 + s2;
  44.             this.str1 = "";
  45.             this.str1 = s1;
  46.         }
  47.  
  48.         public void F0(int n, out string s)
  49.         {
  50.             s = this.str1;
  51.             s = s.Remove(n, 1);
  52.             s = s + s;
  53.         }
  54.  
  55.     }
  56.  
  57.     class Cl2: Ix, Iy
  58.     {
  59.         public string str2;
  60.         public Cl2() { }
  61.         public Cl2(string st)
  62.         {
  63.             this.str2 = st;
  64.         }
  65.  
  66.         public string F0(int n)
  67.         {
  68.             //Console.WriteLine("From class 2, interface Ix");
  69.             string s1 = string.Copy(str2);
  70.             s1 = s1.Substring(n);
  71.             return s1;
  72.         }
  73.         public void F1(int n2)
  74.         {
  75.             //Console.WriteLine("From class 2, interface ???");
  76.             this.str2 = this.str2.Substring(n2);
  77.         }
  78.  
  79.         public void F0(int n, out string s)
  80.         {
  81.             s = this.str2;
  82.             //Console.WriteLine("From class 2, interface Iy");
  83.             s = s.Substring(n);
  84.         }
  85.  
  86.     }
  87.     class Program
  88.     {
  89.         static void Main(string[] args)
  90.         {
  91.             Cl1 x1 = new Cl1("abcdef");
  92.             Cl2 x2 = new Cl2("ABCDEF");
  93.             Cl1 x12 = new Cl1("abcdef");
  94.             Cl2 x22 = new Cl2("ABCDEF");
  95.             x1.F1(2);
  96.             Console.WriteLine("Метод F1 из первого класса: " + x1.str1);
  97.             x2.F1(2);
  98.             Console.WriteLine("Метод F1 из второго класса: " + x2.str2);
  99.             Console.WriteLine("Класс 1, интерфейс Ix: " +((Ix)x12).F0(2));
  100.             Console.WriteLine("Класс 2, интерфейс Ix: " +((Ix)x22).F0(2));
  101.             string s;
  102.             (x12 as Iy).F0(2, out s);
  103.             Console.WriteLine("Метод F0, интерфейс Iy, класс 1:" + s);
  104.             string s2;
  105.             (x22 as Iy).F0(2, out s2);
  106.             Console.WriteLine("Метод F0, интерфейс Iy, класс 2:" + s2);
  107.             Console.ReadLine();
  108.         }
  109.     }
  110. }
  111.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement