How about this for a singleton:
// .NET Singleton
sealed class Singleton
{
private Singleton() {}
public static readonly Singleton Instance = new Singleton();
}
And it is even threadsafe.
This is a good article discussing the singleton pattern:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnbda/html/
singletondespatt.asp
--
Lars
> -----Original Message-----
> From: Moderated discussion of advanced .NET topics.
> [mailto:[EMAIL PROTECTED]]On Behalf Of Jonni Faiga
> Sent: 31 May 2002 10:38
> To: [EMAIL PROTECTED]
> Subject: [ADVANCED-DOTNET] Singleton pattern
>
>
> Hi,
> Bills conclusion that SuppressFinalize is not required implies that
> Samir Bajaj's statement regarding has Singleton code in
> http://msdn.microsoft.com/msdnmag/issues/01/07/patterns/patterns.asp
> is that "all you need to do in the C# version is make sure you have a
> live reference to the singleton object for as long as it's needed." is
> incorrect.
>
>
> btw. Any idea why the Rational XDE generated code for a singleton has a
> public constructor?
>
> public class Singleton
> {
> public void singletonOperation()
> {
> }
>
> public static Singleton getUniqueInstance()
> {
> if(uniqueInstance == null)
> {
> uniqueInstance = new Singleton();
> }
> return uniqueInstance;
> }
>
> public System.Object getSingletonData()
> {
> return singletonData;
> }
>
> public Singleton()
> {
> }
>
> static Singleton uniqueInstance;
> System.Object singletonData;
> }
>
> You can read messages from the Advanced DOTNET archive,
> unsubscribe from Advanced DOTNET, or
> subscribe to other DevelopMentor lists at http://discuss.develop.com.
>
You can read messages from the Advanced DOTNET archive, unsubscribe from Advanced
DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.