Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I do "using namespace.class"?

I was wondering this as I apparently cannot do this. I have added my .dll as as reference and have added using myNamespace; but whenever I want to call one of the functions, I have to use myClass.myMethod(); is there anything I can do so I wont need to reference the class name when calling a procedure? So I would only need myMethod();

like image 781
ohSkittle Avatar asked Jan 02 '15 23:01

ohSkittle


2 Answers

You cannot do that in any way in current C#. using just puts the namespace into your code so you don't have to explicitly write it each time you need it.

If your class is static and you are using C# 6.0, you can do this:

using static System.Console;

private static void Main(string[] args)
{
    WriteLine("test");
}
like image 146
BradleyDotNET Avatar answered Sep 20 '22 12:09

BradleyDotNET


You can't for now. But in C# 6.0 you will be able able to use using directives for static classes.

For example:

using System.Console;
// ...
Write(4);

You can see the detailed list for all features here

like image 29
Selman Genç Avatar answered Sep 20 '22 12:09

Selman Genç