Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace task3
- {
- class Program
- {
- public delegate string SubStrDel(string str, int range);
- public static SubStrDel subStr = Slice;
- public class Slicer
- {
- public string slice { get; set; }
- public string MrSlicer()
- {
- return slice.Substring(0, slice.Length - 2);
- }
- }
- public static string Slice(string str, int range)
- {
- return str.Substring(range);
- }
- public static string Replace(string str, int range)
- {
- return "(Здесь могла быть Ваша реклама)" + str.Substring(range);
- }
- static void Main(string[] args)
- {
- while (true)
- {
- Console.Write("Ваше слово / предложение: ");
- string word = Console.ReadLine();
- try
- {
- Console.Write("Выберите вариант делегата:\n1. Экземляром делегата;\n2. Статическим делегатом;\n3. Классом\n > ");
- int choose = Int32.Parse(Console.ReadLine());
- switch (choose)
- {
- case 1:
- SubStrDel sub = new SubStrDel(Replace);
- Console.WriteLine(sub(word, 1));
- break;
- case 2:
- Console.WriteLine(subStr(word, 2));
- break;
- case 3:
- Slicer slicer = new Slicer();
- slicer.slice = word;
- Console.WriteLine(slicer.MrSlicer());
- break;
- default:
- Console.WriteLine("Данного варианта не существует!");
- break;
- }
- }
- catch (FormatException)
- {
- Console.WriteLine("Вы ввели некорректное значение!");
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment