3 ms·
> I don't think any .NET language can do that Although the CLR does allow for them. Global functions can be emulated: public static GlobalFuncs {
by louthy 10y ago
> I don't think any .NET language can do that
Although the CLR does allow for them.
Global functions can be emulated:
public static GlobalFuncs
{
public string Greet(string x) => $"Hello, {x}";
}
Elsewhere:
using static GlobalFuncs;
public void Test();
{
Greet("HN"); // "Hello, HN"
}
- jarnonijboer 10y agoThis isn't feature that the CLR knows. It is just syntactic sugar from the C# compiler; As it will prepend GlobalFuncs to the Greet method.
- louthy 10y agoSorry, I didn't mean to confuse the issue. The CLR can do global functions. But no .NET language currently supports it. The example I gave was just a way of achieving visually the effect of global functions (which I assumed was the major issue of the OP, because there's no other cost to using static methods than having the qualify them with the type name).