By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,330 Members | 1,262 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,330 IT Pros & Developers. It's quick & easy.

Optional parameters

P: n/a
Does c# support optional parameters in function declarations?
Does it support assignment of default values to arguments, in particular
optional parameters?
If so, can someone point me to or provide an example.
For instance in vb6, you could do the following:
function DoStuff(optional ID as integer = 10, optional Name as string =
"test")
....
end function

--
Frank
Nov 13 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Hi Frank,

I do not think so, you can overload the function, though :

public void DoStuff(){
DoStuff( 10, "test");
}
public void DoStuff( int i, string s){}

Hope this help,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Frank Rizzo" <no****@nospam.com> wrote in message
news:un**************@TK2MSFTNGP12.phx.gbl...
Does c# support optional parameters in function declarations?
Does it support assignment of default values to arguments, in particular
optional parameters?
If so, can someone point me to or provide an example.
For instance in vb6, you could do the following:
function DoStuff(optional ID as integer = 10, optional Name as string =
"test")
...
end function

--
Frank

Nov 13 '05 #2

P: n/a
You could pass an array in to the function containing your
parameters....
-----Original Message-----
Hi Frank,

I do not think so, you can overload the function, though :
public void DoStuff(){
DoStuff( 10, "test");
}
public void DoStuff( int i, string s){}

Hope this help,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Frank Rizzo" <no****@nospam.com> wrote in message
news:un**************@TK2MSFTNGP12.phx.gbl...
Does c# support optional parameters in function declarations? Does it support assignment of default values to arguments, in particular optional parameters?
If so, can someone point me to or provide an example.
For instance in vb6, you could do the following:
function DoStuff(optional ID as integer = 10, optional Name as string = "test")
...
end function

--
Frank

.

Nov 13 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.