Link to home
Start Free TrialLog in
Avatar of paulwhelan
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
ASKER CERTIFIED SOLUTION
Avatar of adathelad
adathelad
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Jase-Coder
Jase-Coder

you not actaully assigning

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
Avatar of paulwhelan

ASKER

thanks