开发者

Access DLL without instantiating

I wrote a simple dll with only 2 functions in it. Is there a way to access these functions without having to instantiate them on every page?

Can't I add them to the web.config somehow as assemblies thus g开发者_如何转开发iving me access to them?


Mark your methods as static and you can call them from anywhere without instantiating the classes.

Your class:

public class MyClass
{
  public static string HelloWorld()
  {
    return "Hello World";
  }
}

Your Page:

string helloWord = MyClass.HelloWorld();

Static Classes and Static Class Members explained.


If you want to access the functions on each page, put them into a base class of all of your pages.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜