simple C# question

  • Thread starter Thread starter Will
  • Start date Start date
W

Will

what is the equivalent in C# to VB's Is Nothing? Check out
the following code snippet:

private SqlConnection objConn;

if (objConn Is Nothing) {
objConn = new SqlConnection(strConnection);
}

I'm converting my coded from vb to C# and I want to
replace objConn Is Nothing with the C# equivalent? I
trried == NULL, but C# doesn't know NULL. Thanks
 
what is the equivalent in C# to VB's Is Nothing? Check out
the following code snippet:

private SqlConnection objConn;

if (objConn Is Nothing) {
objConn = new SqlConnection(strConnection);
}

I'm converting my coded from vb to C# and I want to
replace objConn Is Nothing with the C# equivalent? I
trried == NULL, but C# doesn't know NULL. Thanks

Will,

C# is case sensitive. null is all lowercase letters:

if (objConn == null) {
objConn = new SqlConnection(strConnection);
}

Hope this helps.

Chris.
 
C# uses null (all lowercase). But if you don't initialize a variable it's
going to have an undefined value, make sure you set objConn before you check
it for null (such as in a constructor). If it's an instance variable then it
is going to have a default value but it's better not to rely on that and
always set your variables before using them.

Jerry
 
Back
Top