Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Method overloading question

Status
Not open for further replies.

Laeg

Programmer
Nov 29, 2004
95
0
0
IE
If I have 2 methods of the same name, each taking one parameter. The first takes the parameter by value and the second by reference. When invoking the method how do I specify which version I want to use?

Given
Code:
public class foobar{
...
public foo(int a){}
public foo(ref int a){}
}

how do I say which version of foo I want to call?

Code:
int a = 1;
foobar fb = new foobar();
fb.foo(a); //which foo to call?
 
i'm surprised this compiles. it's certainly pretty poor coding. what does the non-ref one do that the ref one does? it's such poor coding that it smells like hoemwork.

but, whatever, the ref keyword isn't optional, including it should call the second overload.

Code:
fb.foo(a);
fb.foo(ref a);


mr s. <;)

 
Just wondering what uses overloading like this (byval/byref) could have - I can't think of any off the top of my head.

I bet there are some though...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top