I read some articles about static classes but I have some questions:
-
Where take static classes place in memory?
-
According to C# Static Methods :
means that you want the declaration to refer to a single locationIf I use static classes in Asp.Net is it mean I have a location that share between all requests? -
I read in the articles that static classes and static methods are faster that instance-oriented classes,so why I don’t see them in every where.I mean in .Net there is a few static classes and methods exist too.
1.
So it means that the static classes are loaded in memory. This mean that you would not like that all your classes are loaded in memory when your process starts.
2.Static classes in asp.net are saved in application state, so yes, you have a location that share between all requests.
Static methods are useful in asp.net but only if you don’t use static objects inside of the methods because you may get in trouble with different threads accessing modifying the same vaiable.
3.If you use a lot static classes they will be loaded in memory and that’s not necesarly something you would want.
See this link for more information:
static variables in asp.net/C#