
Singleton Design Pattern Question
I have used the singleton design pattern extensively in Java and would like
to use it in
C#. See the following code for my example. I can see where
the Singleton object is created but when is it destroyed? In java, a
Singleton object was destroy when the VM died. When does the .NET VM start
and when does it die (reboot)?
using System;
using System.Collections;
namespace Test
{
public class Singleton {
private static Hashtable ht = new Hashtable();
private static Singleton INSTANCE = new Singleton();
//constructor is private so external objects can not create a new
instance
private Singleton(){
Console.WriteLine("New instance of Singleton");
ht.Add("K1","This is the value for Key1");
ht.Add("K2","This is the value for Key2");
ht.Add("K3","This is the value for Key3");
}
public static String getValue(String key){
return (String)ht[key];
}
}
Quote:
}