Import C # class

I am (very) new to C # and I need to know how to import classes.

In Java, I could just say:

package com.test;
class Test {}

      

And then in some other class:

package com.test2;
import com.test.Test;

      

How can I do this in C #?

+3


source to share


1 answer


Importing namespaces is done in C # with the directive using

:

using com.test;

      

However, there is currently no way to import the class. However, importing classes is a new feature introduced in C # 6 (which will ship with Visual Studio 2015).



In C #, namespaces are semi-equivalent Java packages. To declare a namespace, you just need to do something like this:

namespace com.test
{
    class Test {}
}

      

If the class is declared in a separate assembly (for example, in a class library), simply adding a directive is using

not enough. You must also add a reference to another assembly.

+7


source







All Articles