我創建了一個dll
,我們稱之爲ExampleHelper.dll
。需要從dll實例化類到其他項目中使用
Visual Studio的類庫我已經編譯dll
的結構如下:
namespace ExampleHelper
{
public class Example
{
public string GetExamples(string input)
{
// stuff
}
}
}
所以,我引用它在我的其他項目中,我想用這些ExampleHelper
類,由有關添加在文件的頂部using
行:
using ExampleHelper;
現在,我可以看到,我可以從ExampleHelper
訪問類,它是稱爲Example
。但是,我無法訪問該類中的方法,這意味着我不能寫Example.GetExamples("hello")
,因爲它說GetExamples
不存在。
我注意到,我可以這樣做:
Example e = new Example();
e.GetExamples("hello");
,我當然可以用,但並不覺得我想使用一個輔助方法,每次實例化一個新的對象完全正確。
我做了一件完全錯誤的事情嗎?我的猜測是肯定的,但我無法找到我要去哪裏的錯誤。任何幫助感謝!
如果你不想創建一個實例,使方法(也許是類)靜態... – CodeCaster
也見[什麼是在C#中的「靜態方法?」](https://stackoverflow.com/問題/ 4124102/whats-a-static-method-in-c) – Liam