Создание простейших делегатов - C#
Формулировка задачи:
Создайте экземпляр instDelegate делегата MyDelegate, сообщите с ним два метода экземпляра inst класса MyClass – сначала Method1, затем Method2 - и вызовите их через делегат.
Извиняюсь, wtf?
При проверке на сайте пишет ошибка, ошибку не указывает...
using System;
namespace Less09_task01
{
public delegate void MyDelegate();
class Program
{
static void Main(string[] args)
{
MyClass inst = new MyClass();
MyDelegate instDelegate = new MyDelegate(inst.Method1);
MyDelegate instDelegate1 = new MyDelegate(inst.Method2);
instDelegate();
instDelegate1();
Console.ReadKey();
}
}
class MyClass
{
public void Method1()
{
Console.WriteLine("method1");
}
public void Method2()
{
Console.WriteLine("method2");
}
}
}Решение задачи: «Создание простейших делегатов»
textual
Листинг программы
using System;
namespace Less09_task01
{
public delegate void MyDelegate();
class Program
{
static void Main(string[] args)
{
MyClass inst = new MyClass();
MyDelegate instDelegate = new MyDelegate(inst.Method1);
instDelegate += inst.Method2;
instDelegate();
Console.ReadKey();
}
}
class MyClass
{
public void Method1()
{
Console.WriteLine("method1");
}
public void Method2()
{
Console.WriteLine("method2");
}
}
}