开发者

.Net Static Class Property Scope as it Pertains to the Runtime

开发者 https://www.devze.com 2023-01-24 15:31 出处:网络
Let\'s say that I have two .Net applications running on a single machine. Both applications access a static property in a class. Considering the following scenario in sequential order:

Let's say that I have two .Net applications running on a single machine. Both applications access a static property in a class. Considering the following scenario in sequential order:


Application A

FooClass.MyStaticString = "A";

Application B

FooClass.MyStaticString = "B";

Application A

开发者_JS百科
Console.WriteLine(FooClass.MyStaticString);

Would the result be "A" or "B"? I'm just curious how static .Net statics really are.


They are limited to the specific AppDomain. Each application at a minimum has its own unique AppDomain, so the static property/field is not shared across the applications. It would be "A" as a result. Similarly, if you fired up multiple AppDomains within one process, the static property/field would not be shared between those either.

0

精彩评论

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

关注公众号