开发者

Static classes overview [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 11 years ago.

I read some articles about static classes but I have some questions:

  1. Where take static classes place in memory?

  2. According to C# Static Methods : means that you want the declaration to refer to a single location If I use static classes in Asp.Net is it mean I have a location that share between all requests?

  3. 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.

Static classes are loaded automatically by the .NET Framework common language runtime (CLR) when the program or namespace containing the class is loaded.

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#

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜