Optional parameters

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Frank Rizzo

    #1

    Optional parameters

    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(optiona l ID as integer = 10, optional Name as string =
    "test")
    ....
    end function

    --
    Frank


  • Ignacio Machin

    #2
    Re: Optional parameters

    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" <nospam@nospam. com> wrote in message
    news:unMhYr7SDH A.1948@TK2MSFTN GP12.phx.gbl...[color=blue]
    > 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(optiona l ID as integer = 10, optional Name as string =
    > "test")
    > ...
    > end function
    >
    > --
    > Frank
    >
    >[/color]


    Comment

    • Scott

      #3
      Re: Optional parameters

      You could pass an array in to the function containing your
      parameters....


      [color=blue]
      >-----Original Message-----
      >Hi Frank,
      >
      > I do not think so, you can overload the function,[/color]
      though :[color=blue]
      >
      > public void DoStuff(){
      > DoStuff( 10, "test");
      >}
      >public void DoStuff( int i, string s){}
      >
      >Hope this help,
      >
      >--
      >Ignacio Machin,
      >ignacio.mach in AT dot.state.fl.us
      >Florida Department Of Transportation
      >
      >"Frank Rizzo" <nospam@nospam. com> wrote in message
      >news:unMhYr7SD HA.1948@TK2MSFT NGP12.phx.gbl.. .[color=green]
      >> Does c# support optional parameters in function[/color][/color]
      declarations?[color=blue][color=green]
      >> Does it support assignment of default values to[/color][/color]
      arguments, in particular[color=blue][color=green]
      >> optional parameters?
      >> If so, can someone point me to or provide an example.
      >>
      >>
      >> For instance in vb6, you could do the following:
      >> function DoStuff(optiona l ID as integer = 10, optional[/color][/color]
      Name as string =[color=blue][color=green]
      >> "test")
      >> ...
      >> end function
      >>
      >> --
      >> Frank
      >>
      >>[/color]
      >
      >
      >.
      >[/color]

      Comment

      Working...