Claire,
If you disposed of the instance myClass, then you would have to create a
new instance every time the ClassConnected property is called.
The lifetime of the object assigned to myClass is up to you, but
generally, I don't think that getting rid of the static instance is going to
do you any good.
What is it that you are trying to do exactly?
BTW, the line
if (myClass == null) myClass = new(TMyClass);
Is incorrect, it should be:
if (myClass == null) myClass = new TMyClass();
Assuming it has a parameterless constructor.
--
- Nicholas Paldino [.NET/C# MVP]
-
mv*@spam.guard.caspershouse.com
"Claire" <as*******@ntlworld.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
Ive a static instance of an object in a class. It needs to be Dispose(d)
of when it's finished with.
How do I do this? Or don't I have to worry about it?
Class myClass
{
private static TMyClass myClass = null;
public static bool ClassConnected
{
if (myClass == null) myClass = new(TMyClass);
return myClass.Connected;
}
}