开发者

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:

  1. You add a reference to MyDll.dll within the solution explorer
  2. You include the namespace with using myNamespace;
  3. 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜