hello everyone, just started learning the delegates. There is an example:

// Класс, метод которого будет сообщен с делегатом. static class MyClass { // Создаем статический метод, который планируем сообщить с делегатом. public static void Method() { Console.WriteLine("Строку вывел метод сообщенный с делегатом."); } } // На 21-й строке создаем класс-делегата с именем MyDelegate, // метод, который будет сообщен с экземпляром данного класса-делегата, // не будет ничего принимать и не будет ничего возвращать. public delegate void MyDelegate(); // Создаем класс делегата. (1) class Program { static void Main() { MyDelegate myDelegate = new MyDelegate(MyClass.Method); // Создаем экземпляр делегата. (2) myDelegate.Invoke(); // Вызываем метод сообщенный с делегатом. (3) myDelegate(); // Другой способ вызова метода сообщенного с делегатом. (3') // Delay. Console.ReadKey(); } } 

pay attention to this line:

 public delegate void MyDelegate(); // Создаем класс делегата. (1) 

This course is provided in the form of video lessons, the author says the following:

"note that the method (the default constructor in our delegate class) that will be communicated with this instance of this delegate class - should not accept anything , and also should not return anything "

Here is my question: what the default constructor of the delegate class is: should not accept anything, and should not return anything either "is an axiom for all delegates when created , or is it a specific case because this delegate is In this case, reported with this method:

 public static void Method() { Console.WriteLine("Строку вывел метод сообщенный с делегатом."); } 
  • which takes nothing as parameters and is void; that is, returns nothing, and has this method affected the principles of constructing the delegate and the parameters of its constructor? Ie in the end it's either

  • common axiom

  • specific case of constructing a delegate class reported with this method

Here, in response, I want to get an explanation and an answer, which of the two options is correct.

  • one
    Do not watch video tutorials, they will not teach anything good. - VladD
  • one
    This is a specific case of building a delegate reported with this method. As I understand it, he was just talking about the delegate signature. - MajorMeow
  • one
    @VladD, but in general the designer can return something? well, except for the created object :) - Grundy
  • @Grundy: That's it :) - VladD

1 answer 1

You have delegate type declared as

 public delegate **void** MyDelegate**()**; // Создаем класс делегата. (1) 

void means that delegates of this type point to methods that return nothing.

() means that delegates of this type accept nothing.

For example, if the type were declared as

 public delegate int MyDelegate(string a, string b); 

it could be used for methods that take two strings and return an integer.

  • if I’d say what the designers have to do with it, it would be great :) - Grundy
  • one
    @Grundy I don’t understand where the constructors are - PashaPash