I'm (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 could I do this in C#?
Importing namespaces is accomplished in C# with the using
directive:
using com.test;
However, there is no way, currently, to import a class. Importing classes, however is a new feature which is being introduced in C# 6 (which will come with Visual Studio 2015).
In C#, namespaces are the semi-equivalent of Java's packages. To declare the namespace, you just need to do something like this:
namespace com.test
{
class Test {}
}
If the class is declared in a separate assembly (such as a class library), simply adding the using
directive is not enough. You must also add a reference to the other assembly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With