Using a class file/reference it?
If you use a you assembly reference (myExample.dll), you add like this to the top
using myExa开发者_如何学JAVAmple;
Now if you create a class file, how do you reference it?
Well, in your class file you have the following:
namespace myNamespace
{
public class MyClass
{
public void MyMethod() { }
}
}
Let's assume that you have this in an assembly named MyDll.dll
. You'd use it as follows:
- You add a reference to
MyDll.dll
within the solution explorer - You include the namespace with
using myNamespace;
- Then you can use your class doing
MyClass test = new MyClass();
If you don't add the namespace like I said in 2., you'd use your class like:
myNamespace.MyClass test = new myNamespace.MyClass();
You want to add a using statement for whatever namespace you want to import. Go to the file and see what namespace it wraps the class you're interested in.
You just include the file when compiling the assembly.
You may have to add a using
statement too.
Your question is somehow unclear.
When you define a new class, in another dll, it is enough to reference that dll.
Please note that you might be unable to access that class because of its accessors. Define your class with a public
keyword.
精彩评论