Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Import C# Class

Tags:

c#

import

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#?

like image 256
Lucas Baizer Avatar asked Jul 09 '15 17:07

Lucas Baizer


Video Answer


1 Answers

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.

like image 157
Steven Doggart Avatar answered Oct 16 '22 19:10

Steven Doggart