Click here to Skip to main content
15,890,282 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi

i am studing about the ref and the out keywords to pass argumnets to the method so
in this code the x varible takes the address of the d varible in memeory is that correct 


    class MainProgram
    {
        public static void Main()
        {
            int x;

            Number(out x);

            Console.WriteLine(x);

            Console.ReadKey();
        }
        public static void Number(out int d)
        {
            d = 10;
            d += 2;

            Console.WriteLine(d);
        }
    }
}


What I have tried:

i watched some videos and i understand the main concepts of the ref and out keyword
Posted
Updated 10-Jul-19 8:50am

No, d becomes a reference (think of a pointer-on-steroids) to x, not the other way around. Remember, d is a local variable, so it is created on the stack, and is destroyed when it goes out of scope at the end of the containing method (when it returns.
 
Share this answer
 
Close, but not quite:
Quote:
The out-keyword describes parameters whose actual variable locations are copied onto the stack of the called method
See: https://www.dotnetperls.com/out[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900