Can I import a static class as a namespace to call its methods without specifying a class name in C #?

I make extensive use of the member functions of one particular static class. Specifying a class name every time I call it looks obscene ...

Is it possible to import a static class as a namespace to call its methods without specifying a C # class name?

+6
source share
2 answers

If you want to import it in such a way that its methods are global, no.

However, you can see extension methods. These are static methods that, when importing a class namespace, are displayed as instance methods for the type of their first argument. More details here: http://msdn.microsoft.com/en-us/library/bb383977.aspx

+10
source

The function you were looking for was added in C # 6.0

It is called Using Statics.

Here is a link for additional explanations and examples: https://msdn.microsoft.com/en-us/magazine/dn879355.aspx

+8
source

Source: https://habr.com/ru/post/890311/


All Articles