Advertisement
VictoriaLodochkina

lab 6 z 12 csharp

Oct 20th, 2021
723
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.59 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_z_12_csharp
  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 s = this.str1;
  32.             char ch = s[n];
  33.             string s2 = Convert.ToString(ch);
  34.             s = s.Replace(s2, "+");
  35.             return s;
  36.         }
  37.         void Ix.F1(int n2)
  38.         {
  39.             Console.WriteLine("From class 1, interface Ix");
  40.             char ch = this.str1[n2];
  41.             string s = Convert.ToString(ch);
  42.             this.str1 = this.str1.Replace(s, "+");
  43.         }
  44.  
  45.         public void F0(int n, out string s)
  46.         {
  47.             s = this.str1;
  48.             char ch = s[n];
  49.             string s2 = Convert.ToString(ch);
  50.             s = s.Replace(s2, "+");
  51.         }
  52.  
  53.         void Iy.F1(int n)
  54.         {
  55.             Console.WriteLine("From class 1, interface Iy");
  56.             char ch = this.str1[n];
  57.             string s = Convert.ToString(ch);
  58.             this.str1=this.str1.Replace(s, "+");
  59.         }
  60.  
  61.     }
  62.  
  63.     class Cl2 : Ix, Iy
  64.     {
  65.         public string str2;
  66.         public Cl2() { }
  67.         public Cl2(string st)
  68.         {
  69.             this.str2 = st;
  70.         }
  71.  
  72.         public string F0(int n)
  73.         {
  74.             //Console.WriteLine("From class 2, interface Ix");
  75.             string s1 = string.Copy(str2);
  76.             s1 = s1.Substring(n);
  77.             return s1;
  78.         }
  79.         public void F1(int n2)
  80.         {
  81.             //Console.WriteLine("From class 2, interface ???");
  82.             this.str2 = this.str2.Substring(n2);
  83.         }
  84.  
  85.         public void F0(int n, out string s)
  86.         {
  87.             s = this.str2;
  88.             //Console.WriteLine("From class 2, interface Iy");
  89.             s = s.Substring(n);
  90.         }
  91.  
  92.     }
  93.     class Program
  94.     {
  95.         static void Main(string[] args)
  96.         {
  97.             Cl1 x1 = new Cl1("abcdef");
  98.             (x1 as Ix).F1(2);
  99.             Console.WriteLine(x1.str1);
  100.             Cl1 x12 = new Cl1("abcdef");
  101.             (x12 as Iy).F1(2);
  102.             Console.WriteLine(x12.str1);
  103.             Console.ReadLine();
  104.         }
  105.     }
  106. }
  107.  
  108.  
  109.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement