alexandrheathen

Untitled

Oct 18th, 2018
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.39 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 task3
  8. {
  9.     class Program
  10.     {
  11.         public delegate string SubStrDel(string str, int range);
  12.  
  13.         public static SubStrDel subStr = Slice;
  14.  
  15.         public class Slicer
  16.         {
  17.             public string slice { get; set; }
  18.  
  19.             public string MrSlicer()
  20.             {
  21.                 return slice.Substring(0, slice.Length - 2);
  22.             }
  23.         }
  24.  
  25.         public static string Slice(string str, int range)
  26.         {
  27.             return str.Substring(range);
  28.         }
  29.  
  30.         public static string Replace(string str, int range)
  31.         {
  32.             return "(Здесь могла быть Ваша реклама)" + str.Substring(range);
  33.         }
  34.  
  35.         static void Main(string[] args)
  36.         {
  37.             while (true)
  38.             {
  39.                 Console.Write("Ваше слово / предложение: ");
  40.                 string word = Console.ReadLine();
  41.                 try
  42.                 {
  43.                     Console.Write("Выберите вариант делегата:\n1. Экземляром делегата;\n2. Статическим делегатом;\n3. Классом\n > ");
  44.                     int choose = Int32.Parse(Console.ReadLine());
  45.                     switch (choose)
  46.                     {
  47.                         case 1:
  48.                             SubStrDel sub = new SubStrDel(Replace);
  49.                             Console.WriteLine(sub(word, 1));
  50.                             break;
  51.                         case 2:
  52.                             Console.WriteLine(subStr(word, 2));
  53.                             break;
  54.                         case 3:
  55.                             Slicer slicer = new Slicer();
  56.                             slicer.slice = word;
  57.                             Console.WriteLine(slicer.MrSlicer());
  58.                             break;
  59.                         default:
  60.                             Console.WriteLine("Данного варианта не существует!");
  61.                             break;
  62.                     }
  63.                 }
  64.                 catch (FormatException)
  65.                 {
  66.                     Console.WriteLine("Вы ввели некорректное значение!");
  67.                 }
  68.             }
  69.         }
  70.     }
  71. }
Advertisement
Add Comment
Please, Sign In to add comment