_takumi

Практика по делегатам

Jan 9th, 2020
267
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.30 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 Delegates
  8. {
  9.     public delegate void SayHello(string name);
  10.  
  11.     public static class RussianGreeting
  12.     {
  13.         public static void SayHello(string name)
  14.         {
  15.             Console.WriteLine($"Здравствуйте, {name}");
  16.         }
  17.     }
  18.  
  19.     public static class EnglishGreeting
  20.     {
  21.         public static void SayHello(string name)
  22.         {
  23.             Console.WriteLine($"Hello, {name}");
  24.         }
  25.     }
  26.  
  27.     public static class GermanGreeting
  28.     {
  29.         public static void SayHello(string name)
  30.         {
  31.             Console.WriteLine($"Hallo, {name}");
  32.         }
  33.     }
  34.  
  35.     class Program
  36.     {
  37.  
  38.         static void Main(string[] args)
  39.         {
  40.             Console.WriteLine("Введите имя, с которым надо поздороваться");
  41.             string name = Console.ReadLine();
  42.  
  43.             SayHello russian = RussianGreeting.SayHello;
  44.             SayHello german = GermanGreeting.SayHello;
  45.             SayHello english = EnglishGreeting.SayHello;
  46.             SayHello combinedDelegate = russian + german + english;
  47.  
  48.             combinedDelegate(name);
  49.             Console.ReadKey();
  50.         }
  51.     }
  52. }
Add Comment
Please, Sign In to add comment