作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
是否为进程中的每个 AppDomain 创建了一个公共(public)静态变量的副本,或者它只是整个进程的一个副本?换句话说,如果我从一个 AppDomain 中更改静态变量的值,是否会影响同一进程中另一个 AppDomain 中相同静态变量的值?
最佳答案
正如此示例所证明的,它是每个应用程序域:
public class Foo
{
public static string Bar { get; set; }
}
public class Test
{
public Test()
{
Console.WriteLine("Second AppDomain: {0}", Foo.Bar);
}
}
class Program
{
static void Main()
{
// Set some value in the main appdomain
Foo.Bar = "bar";
Console.WriteLine("Main AppDomain: {0}", Foo.Bar);
// create a second domain
var domain = AppDomain.CreateDomain("SecondAppDomain");
// instantiate the Test class in the second domain
// the constructor of the Test class will print the value
// of Foo.Bar inside this second domain and it will be null
domain.CreateInstance(Assembly.GetExecutingAssembly().FullName, "Test");
}
}
关于.net - 在 .Net 中,公共(public)静态变量的 'Staticness' 是否仅限于 AppDomain 或整个过程?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6562162/
我是一名优秀的程序员,十分优秀!