Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Простой пример применения делегата.
- using System;
- // Объявить тип делегата.
- delegate string StrMod(string str) ;
- class StrMod
- {
- // Заменить пробелы дефисами.
- static string ReplaceSpaces(string s) {
- // ...
- }
- // Удалить пробелы.
- static string RemoveSpaces(string s) {
- // ...
- }
- // Обратить-строку.
- static string Reverse(string s) {
- // ...
- }
- }
- static void Main() {
- // Сконструировать делегат.
- StrMod example = new StrMod(ReplaceSpaces);
- string str;
- // Вызвать методы с помощью делегата.
- str = example("Саша отсосала у Алёши"); Console.WriteLine(str);
- example = new StrMod(RemoveSpaces) ;
- str = example("Саша отсосала у Алёши"); Console.WriteLine(str);
- example = new StrMod(Reverse);
- str = example("Саша отсосала у Алёши"); Console.WriteLine(str);
- }
- } // class
- /*
- Замена пробелов дефисами.
- Удаление пробелов.
- Обращение строки.
- */
Advertisement
Add Comment
Please, Sign In to add comment