Wrox Home  
Search P2P Archive for: Go

  Return to Index  

aspdotnet_website_programming thread: Function Overloading Coding Technique


Message #1 by "T Roach" <troach242@e...> on Fri, 6 Sep 2002 06:11:11
I am working my way thru the book and learning C# as I go.  I noticed 
that in several classes, an overloaded function has 99% the same code it 
it as the others.  Ex. Permission.GetPermissionList() and 
Permission.GetPermissionList(int roleId).  One line of code difference

Is there a way to call one function from another within the class so the 
code is not repeated?  It makes sense, but I can't find syntax like this 
anywhere?!

public DataSet GetPermissionList() {
  Return GetPermissionList(null);
}

Something like that...

Thanks for the help...
Message #2 by "Mike Gale" <info@d...> on Fri, 6 Sep 2002 16:56:41 +1200
I suggest try it in the cases you see.  (Nothing like seeing it work to
help learning!)

I use the approach you mention when creating overloaded function
(calling one overload from the body of another).

Mike Gale, Decision Engineering (NZ) Ltd.

>Is there a way to call one function from another within the class so
the 

Message #3 by "T Roach" <troach242@e...> on Fri, 6 Sep 2002 06:30:52
I think I just worked it out... The function you want to call from the 
other function must be defined above that function.
Ex.
public DataSet GetPermissionList(int roleId) {
// do some stuff
  return permissions;
}

must be defined before..

public DataSet GetPermissionList() {
    return GetPermissionList(-1);
}

I still need to work out the details, but it seems to be possible and 
would definitely make the code easier to maintain.

  Return to Index