Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
School/C# - Beginner (Denis)/Lesson 49/lesson_49.cs
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
77 lines (69 sloc)
1.51 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
delegate (параметры) | |
{ | |
// инструкции | |
} | |
class Program | |
{ | |
delegate void MessageHandler(string message); | |
static void Main(string[] args) | |
{ | |
MessageHandler handler = delegate (string mes) | |
{ | |
Console.WriteLine(mes); | |
}; | |
handler("hello world!"); | |
Console.Read(); | |
} | |
} | |
class Program | |
{ | |
delegate void MessageHandler(string message); | |
static void Main(string[] args) | |
{ | |
ShowMessage("hello!", delegate (string mes) | |
{ | |
Console.WriteLine(mes); | |
}); | |
Console.Read(); | |
} | |
static void ShowMessage(string mes, MessageHandler handler) | |
{ | |
handler(mes); | |
} | |
} | |
class Program | |
{ | |
delegate void MessageHandler(string message); | |
static void Main(string[] args) | |
{ | |
MessageHandler handler = delegate | |
{ | |
Console.WriteLine("анонимный метод"); | |
}; | |
handler("hello world!"); // анонимный метод | |
Console.Read(); | |
} | |
} | |
delegate int Operation(int x, int y); | |
static void Main(string[] args) | |
{ | |
Operation operation = delegate (int x, int y) | |
{ | |
return x + y; | |
}; | |
int d = operation(4, 5); | |
Console.WriteLine(d); // 9 | |
Console.Read(); | |
} | |
delegate int Operation(int x, int y); | |
static void Main(string[] args) | |
{ | |
int z = 8; | |
Operation operation = delegate (int x, int y) | |
{ | |
return x + y + z; | |
}; | |
int d = operation(4, 5); | |
Console.WriteLine(d); // 17 | |
Console.Read(); | |
} |