Deutsch

C# - pattern matching - many discards

10.03.24 12:01
Re: C# - pattern matching - many discards
 
AlexNek патриот
AlexNek
В чем я ошибаюсь?

Глупо будет мне с умным видом рассуждать о языке, на котором не написал ни одной строчки.

Поэтому давайте разбираться вместе.

https://learn.microsoft.com/en-us/dotnet/csharp/programmin...

https://www.c-sharpcorner.com/article/send-method-as-param...


C#

"A delegate is a type that represents references to methods with a particular parameter list and return type"

"Delegates are similar to C++ function pointers, but delegates are fully object-oriented, and unlike C++ pointers to member functions, delegates encapsulate both an object instance and a method."


delegate declaration

public delegate int Operation(int i, int j);

instantiate a delegate

Operation operation = (i, i1) => i + i1;

invoke

int result = operation(1, 2);


Java

"Since Java 1.8 we have the Java.util.Function interface (remember Java uses interfaces to send methods as parameters)."


Interface Function<T,R>


delegate declaration - нет


код похожий на instantiate a delegate

Function<Employee, String> f0 = (e) -> e.toString();


выполнение

String result = f0.apply(e1);

Отличия есть и довольно большие, хотя визуально ничего особенно не видно

 

Перейти на