2011-07-03 13 views

cevap

10

Bu örnekte de kanıtlandığı gibi, bu uygulama alanı sayısı:

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"); 
    } 
} 
+0

Teşekkürler. Şimdiye kadar en iyi cevap! – Harindaka

+1

Örnek programı çalıştırmayı denediğimde, TypeLoadException iletisiyle ileti alıyorum 'Test' türünü yüklenemedi 'ConsoleApplication1, Version = 1.0.0.0, Culture = neutral, PublicKeyToken = null'. HResult 80131522'dir. – DWright

0

Bu uygulama etki alanı ile sınırlıdır, başka bir deyişle, bir değişken değerin her uygulama etki alanı içinde ayrı bir değer olarak bulunmaktadır.

İlgili konular