Allow top-level functions outside classes #8136
Replies: 5 comments 18 replies
-
How do you call this? Do you simply import the namespace and you're able to call the function? |
Beta Was this translation helpful? Give feedback.
-
@KennethHoff, just the way people call global functions in other languages. They are available everywhere. You can call it like And if people created two identical functions with the same name, then the code won't compile. But if they were different in signature, then both functions would be available as overloads. |
Beta Was this translation helpful? Give feedback.
-
See: #1180 |
Beta Was this translation helpful? Give feedback.
-
@HaloFour, that was a long thread. I did not read all of it. Just some comments at the beginning and some comments at the end. And after 7 years the C# team has done nothing related to that request. Is there a specific comment to redirect me to? |
Beta Was this translation helpful? Give feedback.
-
I can understand your plight and desire for this feature, and it’s one that, when I started learning C# (about 15 years ago), I used to wish for myself. However, @HaloFour is right: this is something that can now be done with existing language features. Specifically, If you want to "pollute" the global namespace, |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Let us be able to create a standalone function outside a class or a namespace, like other languages, like JS or Python.
Beta Was this translation helpful? Give feedback.
All reactions