paulwhelan
asked on
By Value / Ref problems
Hi
I do
int i = 0;
MessageBox.Show("i is " + i);
changei(i);
MessageBox.Show("i is " + i);
changeibyref(ref i);
MessageBox.Show("i is " + i);
with
public int changei(int i)
{
return i + 1;
}
public int changeibyref(ref int i)
{
return i + 1;
}
and it say
0
0
0
I thought it should say
0
0
1
Thanks
Paul
I do
int i = 0;
MessageBox.Show("i is " + i);
changei(i);
MessageBox.Show("i is " + i);
changeibyref(ref i);
MessageBox.Show("i is " + i);
with
public int changei(int i)
{
return i + 1;
}
public int changeibyref(ref int i)
{
return i + 1;
}
and it say
0
0
0
I thought it should say
0
0
1
Thanks
Paul
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thanks
i + 1 to i
your just using i in an expression. to modify i you would need to do i = i + i
return i + 1; is like saying return the value of i + 1