VitzzViperzz
Well-known member
Hello,
So I as I have have been working on more complicated C# topics and I cannot seem to grasp some things as easily as I used to.
One of those topics are references!
I think I may have asked this question before but not asked it properly.
Can someone explain what they are used for with some code explanation?
I have looked at these two slices of code but I just cannot understand what is going on.
i is : 21
test is : 21
How?
So I as I have have been working on more complicated C# topics and I cannot seem to grasp some things as easily as I used to.
One of those topics are references!
I think I may have asked this question before but not asked it properly.
Can someone explain what they are used for with some code explanation?
I have looked at these two slices of code but I just cannot understand what is going on.
C#:
public void ModifyAnIntAndButton(ref int value, ref Button button)
{
int i = value;
i *= 5;
value = i - 3;
button = button1;
}
private void button2_Click(object sender, EventArgs e)
{
int q = 100;
Button b = button1;
ModifyAnIntAndButton(ref q, ref b);
Console.WriteLine("q = {0}, b.Text = {1}", q, b.Text);
}
C#:
static void addOneToRefParam ( ref int i )
{
i = i + 1;
Console.WriteLine ( "i is : " + i ) ;
}
test = 20 ;
addOneToRefParam(ref test);
Console.WriteLine ( "test is : " + test ) ;
i is : 21
test is : 21
How?