Gibt es in C# "Function Call Operatoren" wie in C++?
Diese dienen dazu, den Klassenaufrauf wie eine Funktion zu gestalten.
Class Foo
{
int operator()(int a, int b)
{
return a + b;
}
};
int i = foo(1, 2)
warum nicht einfach eine statische funktion?
cSharp Projekte : https://github.com/jogibear9988
s.a. die Antworten in Overloading function call operator in C# (bes. die von "Merlyn Morgan-Graham" - also bzgl. "conversion operators" und "delegates").
@FZelle: Extensionmethods sind m.M.n. damit kein Ersatz (sie sind syntaktisch auch anders aufzurufen, nämlich wie eine normale Methode auch, also mit einem Methodennamen).
Ein Glück, dass es ganz viele unsinnige Dinge aus C++ nicht in C# gibt...
- performance is a feature -
Microsoft MVP - @Website - @AzureStuttgart - github.com/BenjaminAbt - Sustainable Code