By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,660 Members | 1,071 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,660 IT Pros & Developers. It's quick & easy.

C# equivalent of 'undefined'

P: n/a
Bob
IN JScript, we can use the keyword undefined as follows:

if (node!=undefined)
{
//do something
}

What is the equivalent of the above in C#?

Thanks,
Bob
Nov 16 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a

if (node != null)
{
// do something
}

It is the job of the developer to use a null value as meaning "undefined" or unitialized. There is no true "undefined" equivalent
in C#.

If you declare a reference type:

private string mystring;

It will be initialized as "null" within the scope of a class.

If you have a method:

private void MyMethod(string Variable)
{
}

A caller may pass a null value in as "Variable".

If you do not wish to accept null values I might suggest that you then throw an exception, depending on the context of the method:

throw new ArgumentNullException("Variable");

-- Hope this helps.

--
Dave Sexton
ds*************@somethingdigitalBYE-SPAM.com (remove BYE-SPAM)
[Please do not reply by email unless asked to]
-----------------------------------------------------------------------
"Bob" <an*******@discussions.microsoft.com> wrote in message news:21****************************@phx.gbl...
IN JScript, we can use the keyword undefined as follows:

if (node!=undefined)
{
//do something
}

What is the equivalent of the above in C#?

Thanks,
Bob

Nov 16 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.