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.
精彩评论