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" <wswelch@.comcast.net> wrote in
news:08ba01c3627a$38a25240$a001280a@.phx.gbl:
> 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.R. Timmons Consulting, Inc.
http://www.crtimmonsinc.com/
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
"Will" <wswelch@.comcast.net> wrote in message
news:08ba01c3627a$38a25240$a001280a@.phx.gbl...
> 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
Monday, March 26, 2012
simple C# question
Labels:
asp,
code,
equivalent,
following,
net,
objconn,
objconnif,
outthe,
snippetprivate,
sqlconnection
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment