Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

Delegate

//A delegate is an object that knows how to call a method.
delegate int Transformer (int x);
//Transformer is compatible with any method 
//with an int return type and a single int parameter,
int Square (int x) 
{ 
  return x * x; 
}
//Or, more tersely:
int Square (int x) => x * x;
//Assigning a method to a delegate variable creates a delegate instance:
Transformer t = Square;
//You can invoke a delegate instance in the same way as a method:
int answer = t(3);    // answer is 9
Comment

Delegate

class Program
{
    delegate void Message(); // 1. Объявляем делегат
    static void Main()
    {
        Message mes;            // 2. Создаем переменную делегата
        mes = Hello;            // 3. Присваиваем этой переменной адрес метода
        mes();                  // 4. Вызываем метод
 
        void Hello() => Console.WriteLine("Hello METANIT.COM");
    }
}
Comment

PREVIOUS NEXT
Code Example
Csharp :: pause and resume thread C# 
Csharp :: what is implicit keyword c# 
Csharp :: parse error message: could not create type webservice.webservice asp .net 
Csharp :: c# ushort 
Csharp :: conditional middleware .net core 
Csharp :: show double in textbox c# 
Csharp :: c# get error message from cmd command 
Csharp :: c# aabb box rotate 
Csharp :: c# generate random date of birth but over 18 
Csharp :: unity mouse click 
Csharp :: c# add field to expando object 
Csharp :: C# assign integer 
Csharp :: c# convert address to int 
Csharp :: how to use a round image unity 
Csharp :: vb.net get double item in list osf string 
Csharp :: asp.netcore: develop on win10 run on ubuntu 
Csharp :: where are the viwes in .net core publish 
Csharp :: Custom Circular Picture Box C# win Form app 
Csharp :: #StopRape 
Csharp :: system.collections.generic.list 1 system.int32 c# 
Csharp :: call a .NET assembly from C or c++ 
Csharp :: exception meaning in .net core 
Csharp :: in clause db2 c# 
Csharp :: c# uint 
Csharp :: stackoverflow array c# 
Csharp :: c# fileinfo filename without extension 
Csharp :: c# list double min max 
Csharp :: c# fill values of child from parent 
Csharp :: what loops are entry controlled c# 
Csharp :: Initalize C# project in VS Code 
ADD CONTENT
Topic
Content
Source link
Name
4+1 =