Well, yes, you can do something like this:
public class OpenDoorSingleton1
{
private static OpenDoorSingleton1 _instance;
private string _aString;
public string AString
{
set { if (_instance != null) _instance._aString = value; }
get
{
if (_instance != null)
{
return _instance._aString;
}
else
{
return string.Empty;
}
}
}
protected OpenDoorSingleton1()
{
}
public static OpenDoorSingleton1 StaticInstantiate()
{
if (_instance == null) _instance = new OpenDoorSingleton1();
return _instance;
}
public OpenDoorSingleton1(string astring)
{
_instance = StaticInstantiate();
_instance.AString = astring;
}
}
This has a public constructor that lets you use parameters, but, look at all the trouble you had to go through to avoid recursion and stack overflow here !
I would never use code like this: you are hiding the intention to make this a one-and-only-one instance Class !
See: Jon Skeet: [
^], and, the DoFactory sample for Singleton (free): [
^].