Answer the question
In order to leave comments, you need to log in
Delegates and their instances?
hello everyone, just started learning delegates. and so far I understood the following:
in order to create a delegate, we first create a delegate class (yes, yes, I know that this is not quite the correct name)
public delegate void MyDelegate(); // Создаем класс делегата. (1)
// Создаем статический метод, который планируем сообщить с делегатом.
public static void Method()
{
Console.WriteLine("Строку вывел метод сообщенный с делегатом.");
}
MyDelegate myDelegate = new MyDelegate(MyClass.Method); // Создаем экземпляр делегата. (2)
// Создаем статический метод, который планируем сообщить с делегатом.
public static void MyMethod()
{
Console.WriteLine("Строку вывел метод сообщенный с делегатом.");
}
MyDelegate myDelegate = new MyDelegate(MyClass.MyMethod); // Создаем экземпляр делегата. (2)
Answer the question
In order to leave comments, you need to log in
Yes, you almost got it right. For methods with the same signature, one delegate is enough, for a method with a different signature, another delegate is required.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question