Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Microsoft .NET parser C# error ?

Microsoft .NET parser C# error ?

Scheduled Pinned Locked Moved C#
csharphelpquestion
5 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • I Offline
    I Offline
    identy
    wrote on last edited by
    #1

    if (foo == null) System.Data.Foo _Foo = new System.Data.Foo; ∙ ^ Error ^ if (foo == null) { System.Data.Foo _Foo = new System.Data.Foo; } ∙ ^ No Error ^ Becouse?:eek:

    J 1 Reply Last reply
    0
    • I identy

      if (foo == null) System.Data.Foo _Foo = new System.Data.Foo; ∙ ^ Error ^ if (foo == null) { System.Data.Foo _Foo = new System.Data.Foo; } ∙ ^ No Error ^ Becouse?:eek:

      J Offline
      J Offline
      J Dunlap
      wrote on last edited by
      #2

      You can't define a variable in an inline if statement. The correct way would be:

      System.Data.Foo _Foo=null;
      if(foo==null)
      _Foo = new System.Data.Foo;

      //or better yet:
      System.Data.Foo _Foo=(foo==null ? new System.Data.Foo : null);

      **"Peace is not merely a distant goal that we seek, but a means by which we arrive at that goal." -- Martin Luther King Jr.

      FLUID UI Toolkit | FloodFill in C# & GDI+**

      U A 2 Replies Last reply
      0
      • J J Dunlap

        You can't define a variable in an inline if statement. The correct way would be:

        System.Data.Foo _Foo=null;
        if(foo==null)
        _Foo = new System.Data.Foo;

        //or better yet:
        System.Data.Foo _Foo=(foo==null ? new System.Data.Foo : null);

        **"Peace is not merely a distant goal that we seek, but a means by which we arrive at that goal." -- Martin Luther King Jr.

        FLUID UI Toolkit | FloodFill in C# & GDI+**

        U Offline
        U Offline
        User 260964
        wrote on last edited by
        #3

        If you use:

        if (foo == null)
        {
        System.Data.Foo _Foo = new System.Data.Foo;
        }

        Now _Foo is only available within the { and }. Now, if you could use the short version:

        if (foo == null)
        System.Data.Foo _Foo = new System.Data.Foo;

        ...then where would _Foo be available? In the { and }, which you left out, or in the parent's context (e.g. between the methods { and })? Because of this confusion, it is not possible.

        I 1 Reply Last reply
        0
        • J J Dunlap

          You can't define a variable in an inline if statement. The correct way would be:

          System.Data.Foo _Foo=null;
          if(foo==null)
          _Foo = new System.Data.Foo;

          //or better yet:
          System.Data.Foo _Foo=(foo==null ? new System.Data.Foo : null);

          **"Peace is not merely a distant goal that we seek, but a means by which we arrive at that goal." -- Martin Luther King Jr.

          FLUID UI Toolkit | FloodFill in C# & GDI+**

          A Offline
          A Offline
          Anonymous
          wrote on last edited by
          #4

          If you use:

          if (foo == null)
          {
          System.Data.Foo _Foo = new System.Data.Foo;
          }

          Now _Foo is only available within the { and }. Now, if you could use the short version:

          if (foo == null)
          System.Data.Foo _Foo = new System.Data.Foo;

          ...then where would _Foo be available? In the { and }, which you left out, or in the parent's context (e.g. between the methods { and })? Because of this confusion, it is not possible.

          1 Reply Last reply
          0
          • U User 260964

            If you use:

            if (foo == null)
            {
            System.Data.Foo _Foo = new System.Data.Foo;
            }

            Now _Foo is only available within the { and }. Now, if you could use the short version:

            if (foo == null)
            System.Data.Foo _Foo = new System.Data.Foo;

            ...then where would _Foo be available? In the { and }, which you left out, or in the parent's context (e.g. between the methods { and })? Because of this confusion, it is not possible.

            I Offline
            I Offline
            identy
            wrote on last edited by
            #5

            yes correct but i see the c# schema ambiguous :doh:;)

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups