simple C# question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Will

    #1

    simple C# question

    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(s trConnection);
    }

    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
  • Chris R. Timmons

    #2
    Re: simple C# question

    "Will" <wswelch@comcas t.net> wrote in
    news:08ba01c362 7a$38a25240$a00 1280a@phx.gbl:
    [color=blue]
    > 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(s trConnection);
    > }
    >
    > 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[/color]

    Will,

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

    if (objConn == null) {
    objConn = new SqlConnection(s trConnection);
    }

    Hope this helps.

    Chris.
    -------------
    C.R. Timmons Consulting, Inc.

    Comment

    • Jerry III

      #3
      Re: simple C# question

      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@comcas t.net> wrote in message
      news:08ba01c362 7a$38a25240$a00 1280a@phx.gbl.. .[color=blue]
      > 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(s trConnection);
      > }
      >
      > 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[/color]


      Comment

      Working...