C# 03.12.2023

This commit is contained in:
StNicolay 2023-12-03 12:08:31 +03:00
parent 352cfb4cdf
commit fee06cf5f7

View File

@ -994,3 +994,19 @@ class Hello
```C# ```C#
delegate T Operation<T, K>(K val); delegate T Operation<T, K>(K val);
``` ```
## Анонимные методы
```C#
string foo = "Foo";
Func a = delegate(string a) {
Console.WriteLine(a);
};
Func b = (a) => Console.WriteLine(a);
Func c = delegate { // Мы аргументы не используем, поэтому скобки можно не писать
Console.WriteLine(foo); // Можно ссылаться на локальные переменные
};
var a = (string a, string b) => Console.WriteLine(a+b); // Неявная типизация
delegate void Func(string a);
```