C# equivalent of C++ NULL pointers for objects?

I'm trying to improve my understanding of C#.

In C++ I could use NULL objects to check for the existance of an object, which gives the following consise pattern:

C++

CMyClass* pMyObject = NULL;
if ((pMyObject = GetMyObject()) != NULL)
{
// Got an existing object
}
else
{
pMyObject = new CMyClass("SomeArgument");
}
pMyObject->MyMethod();

What's the equivalent of this in C#. The nearest I've come to is this:

C#

CMyClass MyObject; // Default MyObject
if (MyObjectAlreadyExists())
{
// Overwrite default MyObject.
MyObject = GetMyObject();
}
else
{
// Overwrite default MyObject.
MyObject = new CMyClass("SomeArgument");
}
MyObject.MyMethod();

I don't like this because:

I have to create a default MyObject, and then throw it away when I overwrite it, which seems inefficient. I don't want to use the object type instead as I lose type checking, and have to then cast to CMyObject.
I have to separate checking whether MyObject already exists from getting it.

Am I missing something?
[1181 byte] By [astanley] at [2007-11-18 17:46:03]
# 1 Re: C# equivalent of C++ NULL pointers for objects?
Originally posted by astanley
C#
//somewhere in your class
CMyClass MyObject = null;

//somewhere in some function
if (MyObject!=null)
{
// Overwrite default MyObject.
MyObject = GetMyObject();
}
else
{
// Overwrite default MyObject.
MyObject = new CMyClass("SomeArgument");
}
MyObject.MyMethod();
Andy Tacker at 2007-11-9 1:36:51 >
# 2 Re: C# equivalent of C++ NULL pointers for objects?
CMyClass MyObject;
Does not create an object. MyObject is effectively a pointer and at this point contains null. (I think).

CMyClass pMyObject = null;
if ((pMyObject = GetMyObject()) != null)
{
// Got an existing object
}
else
{
pMyObject = new CMyClass("SomeArgument");
}
pMyObject.MyMethod();
Norfy at 2007-11-9 1:37:50 >
# 3 Re: C# equivalent of C++ NULL pointers for objects?
Thanks guys; I remember now reading that you have to use new to create an object. The implications didn't sink in, but they have now!
astanley at 2007-11-9 1:38:48 >