Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I make extensive use of member functions of one specific static class. Specifying the class name every time I call it's methods looks nasty...

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

like image 771
Ivan Avatar asked Jun 11 '11 23:06

Ivan


People also ask

Can we call static method without class name in C#?

Static methods can be called without creating an object. You cannot call static methods using an object of the non-static class. The static methods can only call other static methods and access static members. You cannot access non-static members of the class in the static methods.

Can you use a class name to call a static method?

Static methods are the methods in Java that can be called without creating an object of class. They are referenced by the class name itself or reference to the Object of that class.

What is static import in C#?

This modifier was introduced in C# 10. The static modifier imports the static members and nested types from a single type rather than importing all the types in a namespace.

Can I inherit static class in C#?

Can we inherit Static Class in C# ? NO, we can not inherit static class in c# because they are sealed and abstract.


1 Answers

The feature you were looking for was added within C# 6.0

It's called "Using Static".

Here's the link for more explanations and examples: https://msdn.microsoft.com/en-us/magazine/dn879355.aspx

like image 141
papatwika Avatar answered Oct 03 '22 01:10

papatwika