D
Daniel
Hey guys
I need some clarification.
The ref keyword means that you pass in a reference to an object or variable,
is it like the & and * of c++?
What i don't understand is, in c#, it always uses reference by i thought,
or is it only refs on classes?
so if i do
someobj so = new someObj(); //so memory allocated
so.someVar = 10; //somevar set to 10
someobj so2 = so; //they now equal each other, so2 is using a ref as we did
not clone it
so2.someVar = 20; //when we do this, so.someVar also becomes 20
Console.Writeline(so.someVar.ToString());
//would print out 20
Isn't that right? If that is the case, why the ref keyword and when would
you need it?
I need some clarification.
The ref keyword means that you pass in a reference to an object or variable,
is it like the & and * of c++?
What i don't understand is, in c#, it always uses reference by i thought,
or is it only refs on classes?
so if i do
someobj so = new someObj(); //so memory allocated
so.someVar = 10; //somevar set to 10
someobj so2 = so; //they now equal each other, so2 is using a ref as we did
not clone it
so2.someVar = 20; //when we do this, so.someVar also becomes 20
Console.Writeline(so.someVar.ToString());
//would print out 20
Isn't that right? If that is the case, why the ref keyword and when would
you need it?