Using a class file/reference it?

后端 未结 4 1962
终归单人心
终归单人心 2020-12-06 22:47

If you use a you assembly reference (myExample.dll), you add like this to the top

using myExample;

Now if you create a class file, how do y

相关标签:
4条回答
  • 2020-12-06 23:22

    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 讨论(0)
  • 2020-12-06 23:25

    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();
    
    0 讨论(0)
  • 2020-12-06 23:37

    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.

    0 讨论(0)
  • 2020-12-06 23:38

    You just include the file when compiling the assembly.

    You may have to add a using statement too.

    0 讨论(0)
提交回复
热议问题