Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

By Value / Ref problems

Posted on 2006-05-09
3
Medium Priority
?
197 Views
Last Modified: 2010-04-16
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
0
Comment
Question by:paulwhelan
3 Comments
 
LVL 23

Accepted Solution

by:
adathelad earned 120 total points
ID: 16638178
Hi,

It's because your methods don't actually alter the value of i. Try:

public int changei(int i)
        {
            i++;
        }

        public int changeibyref(ref int i)
        {
            i++;
        }
0
 
LVL 11

Expert Comment

by:Jase-Coder
ID: 16638182
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
0
 

Author Comment

by:paulwhelan
ID: 16638245
thanks
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Screencast - Getting to Know the Pipeline
How can you see what you are working on when you want to see it while you to save a copy? Add a "Save As" icon to the Quick Access Toolbar, or QAT. That way, when you save a copy of a query, form, report, or other object you are modifying, you…
Suggested Courses

571 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question