View Single Post
Old Apr 26th, 2005, 12:14 PM   #1
Arla
Professional Programmer
 
Arla's Avatar
 
Join Date: Mar 2005
Posts: 343
Rep Power: 4 Arla is on a distinguished road
A standards question, optional inputs into Methods

I'm creating a few methods that have a number of optional inputs

Quick example, say you have a method that prints Hello <name> where <name> is optional input parameter (I know, it's a ridiculously simple example, but bare with me)

so you have two options

I can do

public void PrintHi()
{
  code
}

public void PrintHi(string name)
{
  code
}

which would work fine, but when you have say 10 optional variables and you can have any combinations of them it's quite a lot of different methods (plus you start running into issues if all your variables are of the same type). However the other way, just having one method with the variables all in, but allowing null/0/? inputs for the optional portions seems somewhat clumsy, anyone have other ideas? or other ways this "should" be done?
Arla is offline   Reply With Quote