Click here to Skip to main content
15,899,026 members
Home / Discussions / C#
   

C#

 
GeneralRe: Default parameter in Method Pin
emran8345-Feb-06 22:15
emran8345-Feb-06 22:15 
AnswerRe: Default parameter in Method Pin
ryancrawcour5-Feb-06 21:49
ryancrawcour5-Feb-06 21:49 
you could do something like the following;

class ParameterClass
{
public string Name;
public int IDNumber;

public ParameterClass()
{
//set some default values;
//since both fields are public they can
//be overridden if necessary
this.Name = "";
this.IDNumber = 0;
}
}
class OptionalParameters
{
[STAThread]
static void Main(string[] args)
{

//instantiate a parameter class object
//and override the name field
ParameterClass c = new ParameterClass();
c.Name = "Lamont Adams";
optionalObject(c);

//show that the changed ID came back
Console.WriteLine("c.IDNumber={0}",c.IDNumber);

//call the method with only defaults
optionalObject(new ParameterClass());

//pause so we can see the output
Console.ReadLine();
}
public static void optionalObject(ParameterClass arg)
{
//because the parameters received are encapsulated
//in an object, they are all optional but have
//a valid state even if not explicitly set by the caller
Console.WriteLine("arg.Name={0}, arg.IDNumber={1}", arg.Name, arg.IDNumber);

//change one of the field values
arg.IDNumber = 10;
}
}


this way you don't have to have an overload for every single combination of parameters.
hope this helps...
GeneralRe: Default parameter in Method Pin
emran8345-Feb-06 22:19
emran8345-Feb-06 22:19 
GeneralRe: Default parameter in Method Pin
ryancrawcour5-Feb-06 22:23
ryancrawcour5-Feb-06 22:23 
QuestionRestore DataBase Using SQLDMO Pin
chudapji5-Feb-06 16:55
chudapji5-Feb-06 16:55 
QuestionWindow Form frozen after calling method Show() Pin
bc11185-Feb-06 16:34
bc11185-Feb-06 16:34 
AnswerRe: Window Form frozen after calling method Show() Pin
Christian Graus5-Feb-06 16:42
protectorChristian Graus5-Feb-06 16:42 
AnswerRe: Window Form frozen after calling method Show() Pin
S. Senthil Kumar5-Feb-06 18:14
S. Senthil Kumar5-Feb-06 18:14 
GeneralRe: Window Form frozen after calling method Show() Pin
bc11185-Feb-06 18:45
bc11185-Feb-06 18:45 
GeneralRe: Window Form frozen after calling method Show() Pin
S. Senthil Kumar6-Feb-06 9:52
S. Senthil Kumar6-Feb-06 9:52 
QuestionLaunch and focus webpage from windows form Pin
jshultz5-Feb-06 12:15
jshultz5-Feb-06 12:15 
Question.xsd ordinal Pin
fmardani5-Feb-06 10:58
fmardani5-Feb-06 10:58 
QuestionMultiple font types in richtextbox? Pin
Xodiak5-Feb-06 9:58
Xodiak5-Feb-06 9:58 
AnswerRe: Multiple font types in richtextbox? Pin
leppie5-Feb-06 12:03
leppie5-Feb-06 12:03 
GeneralRe: Multiple font types in richtextbox? Pin
Xodiak5-Feb-06 12:49
Xodiak5-Feb-06 12:49 
GeneralRe: Font Embedding Pin
emran8345-Feb-06 17:15
emran8345-Feb-06 17:15 
GeneralRe: Font Embedding Pin
Dave Kreskowiak6-Feb-06 6:29
mveDave Kreskowiak6-Feb-06 6:29 
QuestionDrop Down menu on a website and tabs on a website Pin
naglbitur5-Feb-06 8:40
naglbitur5-Feb-06 8:40 
QuestionHTML interfaces Pin
Mridang Agarwalla5-Feb-06 6:22
Mridang Agarwalla5-Feb-06 6:22 
AnswerRe: HTML interfaces Pin
leppie5-Feb-06 8:14
leppie5-Feb-06 8:14 
Questionhow i can work with struct and union(union in struct .etc) Pin
gary.ruan5-Feb-06 0:49
gary.ruan5-Feb-06 0:49 
AnswerRe: how i can work with struct and union(union in struct .etc) Pin
Dave Kreskowiak5-Feb-06 5:24
mveDave Kreskowiak5-Feb-06 5:24 
GeneralRe: how i can work with struct and union(union in struct .etc) Pin
gary.ruan6-Feb-06 12:57
gary.ruan6-Feb-06 12:57 
GeneralRe: how i can work with struct and union(union in struct .etc) Pin
Dave Kreskowiak6-Feb-06 14:25
mveDave Kreskowiak6-Feb-06 14:25 
Questiongetting window handles Pin
Mridang Agarwalla4-Feb-06 23:37
Mridang Agarwalla4-Feb-06 23:37 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.