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 Delegates
- {
- public delegate void SayHello(string name);
- public static class RussianGreeting
- {
- public static void SayHello(string name)
- {
- Console.WriteLine($"Здравствуйте, {name}");
- }
- }
- public static class EnglishGreeting
- {
- public static void SayHello(string name)
- {
- Console.WriteLine($"Hello, {name}");
- }
- }
- public static class GermanGreeting
- {
- public static void SayHello(string name)
- {
- Console.WriteLine($"Hallo, {name}");
- }
- }
- class Program
- {
- static void Main(string[] args)
- {
- Console.WriteLine("Введите имя, с которым надо поздороваться");
- string name = Console.ReadLine();
- SayHello russian = RussianGreeting.SayHello;
- SayHello german = GermanGreeting.SayHello;
- SayHello english = EnglishGreeting.SayHello;
- SayHello combinedDelegate = russian + german + english;
- combinedDelegate(name);
- Console.ReadKey();
- }
- }
- }
Add Comment
Please, Sign In to add comment