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. ref vs. out keyword

ref vs. out keyword

Scheduled Pinned Locked Moved C#
visual-studioquestion
6 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.
  • Y Offline
    Y Offline
    Yaakov Davis
    wrote on last edited by
    #1

    What are the differences, if any? Thanks, Yaakov

    C 1 Reply Last reply
    0
    • Y Yaakov Davis

      What are the differences, if any? Thanks, Yaakov

      C Offline
      C Offline
      Charlie Williams
      wrote on last edited by
      #2

      When using out, the parameter needn't be initialized before being passed to into the method, and it must be assigned a value before the method exits. If you need more info, I'd suggest looking in the docs[^]. Charlie if(!curlies){ return; }

      Y 1 Reply Last reply
      0
      • C Charlie Williams

        When using out, the parameter needn't be initialized before being passed to into the method, and it must be assigned a value before the method exits. If you need more info, I'd suggest looking in the docs[^]. Charlie if(!curlies){ return; }

        Y Offline
        Y Offline
        Yaakov Davis
        wrote on last edited by
        #3

        Thanks a lot. Actually, I've read rhe docs before, but I didn't notice this difference. Yaakov.

        L 1 Reply Last reply
        0
        • Y Yaakov Davis

          Thanks a lot. Actually, I've read rhe docs before, but I didn't notice this difference. Yaakov.

          L Offline
          L Offline
          leppie
          wrote on last edited by
          #4

          int a,b,c,d,e,f,g = foo(out a, out b, out c, out d, out e, out f);

          vs

          int a,b,c,d,e,f;
          a=b=c=d=e=f=0;
          int g = foo(ref a, ref b, ref c, ref d, ref e, ref f);

          so, about 2 lines :-> top secret
          Download xacc-ide 0.0.3 now!
          See some screenshots

          Y R 2 Replies Last reply
          0
          • L leppie

            int a,b,c,d,e,f,g = foo(out a, out b, out c, out d, out e, out f);

            vs

            int a,b,c,d,e,f;
            a=b=c=d=e=f=0;
            int g = foo(ref a, ref b, ref c, ref d, ref e, ref f);

            so, about 2 lines :-> top secret
            Download xacc-ide 0.0.3 now!
            See some screenshots

            Y Offline
            Y Offline
            Yaakov Davis
            wrote on last edited by
            #5

            :rolleyes:

            1 Reply Last reply
            0
            • L leppie

              int a,b,c,d,e,f,g = foo(out a, out b, out c, out d, out e, out f);

              vs

              int a,b,c,d,e,f;
              a=b=c=d=e=f=0;
              int g = foo(ref a, ref b, ref c, ref d, ref e, ref f);

              so, about 2 lines :-> top secret
              Download xacc-ide 0.0.3 now!
              See some screenshots

              R Offline
              R Offline
              Robert Rohde
              wrote on last edited by
              #6

              Nice! I didnt know that one. But I wonder if it is good style to declare more than one variable on one line. Most coding styles would forbid it.

              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