Is there "Default Peremeter" in C#?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Peter Koen

    #16
    Re: Is there "Defaul t Peremeter" in C#?

    "news.microsoft .com" <anonymouse@dis cussions.micros oft.com> wrote in
    news:O6qwLsAnDH A.1960@TK2MSFTN GP12.phx.gbl:
    [color=blue]
    > actually news.microsoft. com is the default user for posts via
    > msdn.microsoft. com web site.[/color]

    And why do you have an Outlook Express Posting Header and a typo in
    anonymous(e)???

    From: "news.microsoft .com" <anonymouse@dis cussions.micros oft.com>
    Subject: Re: Is there "Default Peremeter" in C#?
    X-Newsreader: Microsoft Outlook Express 6.00.2800.1106
    X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106
    NNTP-Posting-Host: h89n2fls31o1102 .telia.com 217.210.97.89

    --
    best regards

    Peter Koen
    -----------------------------------
    MCAD, CAI/R, CAI/S, CASE/RS, CAT/RS

    Comment

    • William Ryan

      #17
      Re: Is there &quot;Defaul t Peremeter&quot; in C#?

      When I looked at the IL, I did see the option param so I wasn't sure what he
      means by "Under the hood" but the inference I got was that ultimately,
      that's what's happening (an Option compiles down to an overload). I reread
      the article..

      (It's the last tip)

      Here's the two parts that he mentions:

      <<Method overloading lets you create multiple interface signatures for the
      same method. This feature is not unique to C#. VB .NET also supports it, for
      example, by letting you overload class constructors. VB .NET also uses
      method overloading under the hood whenever you use the Optional keyword in a
      method signature. I'll illustrate with an example. The VB .NET function
      InitSqlCommand initializes and returns an ADO.NET SqlCommand object. The
      function accepts an OLE DB connection string and optionally accepts a
      command timeout value, which defaults to 180 seconds:>>
      And :

      <<The key issue here is that C# doesn't support the kinds of shortcuts VB
      ..NET developers are used to. The benefit of the extra work is you get a
      better understanding of what the compiler is really doing. How many VB .NET
      developers realize the Optional keyword is a shortcut for method
      overloading? In C# you need to know!>>

      "Daniel O'Connell" <onyxkirx@--NOSPAM--comcast.net> wrote in message
      news:dJYmb.3749 0$Tr4.73156@att bi_s03...[color=blue]
      >
      > "William Ryan" <dotnetguru@nos pam.comcast.net > wrote in message
      > news:uFOHjzAnDH A.3504@TK2MSFTN GP11.phx.gbl...[color=green]
      > > According to C# Pro magazine, all the underlying code in VB.NET does[/color][/color]
      when[color=blue][color=green]
      > > you use Optional Params is write the overload for you.... I've looked[/color][/color]
      at[color=blue][color=green]
      > > the IL and couldn't verify it, but I'm far from an expert in IL.
      > >[/color]
      > Thats not true in any manner I've ever seen. I suspect that article was
      > incorrect, ;). IL provides full support for declaring optional arguments,
      > with the OptionalAttribu te attribute and the .param attribute in IL,[/color]
      however[color=blue]
      > it is just information, the language compiler is required to handle using
      > that information to use optional attributes.
      >[color=green]
      > > I agree too, optionals are eveil.
      > > "David Sworder" <dsworder@cts.c om> wrote in message
      > > news:%23LOSooAn DHA.684@TK2MSFT NGP09.phx.gbl.. .[color=darkred]
      > > > > "news.microsoft .com" <anonymouse@dis cussions.micros oft.com> schrieb[/color][/color][/color]
      im[color=blue][color=green][color=darkred]
      > > > > Newsbeitrag news:#SaStl9mDH A.3316@TK2MSFTN GP11.phx.gbl...
      > > > > > C# has no default parameters, it uses overloading isntead.
      > > > >
      > > > > You name isn't really news.microsoft. com, is it?
      > > > >
      > > >
      > > > Yeah, I've noticed that guy too. My suspicion is that
      > > > "news.microsoft .com" is an Agent. Everyone who has tried to fight this[/color]
      > > agent[color=darkred]
      > > > has died. Be extremely careful. Default Params are useful, but they[/color][/color]
      > aren't[color=green][color=darkred]
      > > > worth dieing for....
      > > >
      > > >[/color]
      > >
      > >[/color]
      >
      >[/color]


      Comment

      • news.microsoft.com

        #18
        Re: Is there &quot;Defaul t Peremeter&quot; in C#?

        And i care?



        "|{evin" <You@dont.nee d> wrote in message
        news:ksoopvkiev q0mlqq2foa53ncq 65u6ron97@4ax.c om...[color=blue]
        > On Sun, 26 Oct 2003 22:53:12 +0100, "news.microsoft .com"
        > <anonymouse@dis cussions.micros oft.com> wrote:
        >[color=green]
        > >actually news.microsoft. com is the default user for posts via
        > >msdn.microsoft .com web site.
        > >
        > >[/color]
        > That's great, only you aren't using the CDO interface.
        >[/color]


        Comment

        • Daniel O'Connell

          #19
          Re: Is there &quot;Defaul t Peremeter&quot; in C#?


          "William Ryan" <dotnetguru@nos pam.comcast.net > wrote in message
          news:uw8mpMDnDH A.2424@TK2MSFTN GP10.phx.gbl...[color=blue]
          > When I looked at the IL, I did see the option param so I wasn't sure what[/color]
          he[color=blue]
          > means by "Under the hood" but the inference I got was that ultimately,
          > that's what's happening (an Option compiles down to an overload). I[/color]
          reread[color=blue]
          > the article..
          > http://www.c-sharppro.com/features/2...200310jh_f.asp
          > (It's the last tip)
          >
          > Here's the two parts that he mentions:
          >
          > <<Method overloading lets you create multiple interface signatures for the
          > same method. This feature is not unique to C#. VB .NET also supports it,[/color]
          for[color=blue]
          > example, by letting you overload class constructors. VB .NET also uses
          > method overloading under the hood whenever you use the Optional keyword in[/color]
          a[color=blue]
          > method signature. I'll illustrate with an example. The VB .NET function
          > InitSqlCommand initializes and returns an ADO.NET SqlCommand object. The
          > function accepts an OLE DB connection string and optionally accepts a
          > command timeout value, which defaults to 180 seconds:>>
          > And :
          >
          > <<The key issue here is that C# doesn't support the kinds of shortcuts VB
          > .NET developers are used to. The benefit of the extra work is you get a
          > better understanding of what the compiler is really doing. How many VB[/color]
          ..NET[color=blue]
          > developers realize the Optional keyword is a shortcut for method
          > overloading? In C# you need to know!>>
          >[/color]

          I wonder where that came from, I don't think its accurate...Ther e are
          substantial differences between the different methods. Maybe I should write
          the author and ask for clarification.
          Anyway, I think we've been over this before(maybe over teh same article?) bu
          heres a rundown for anyone who is interested:

          Method Overloading:
          Multiple methods with different parameter sets.
          If used to provide default parameters, parameters are loaded in the method.
          Client code does not need to recompile to effect a change in behaviour

          Optional Parameters:
          Single method with a single parameter set.
          Can be overloaded as long as the methods differ by more than optional
          parameters(in VB.NET atleast)
          Default parameters are loaded by the caller. Breaks versioning in some cases
          because client code must be recompiled for values to change.
          here is some sample IL that shows a method with optional parameters and an
          overload of that method.

          optional parameters:
          ..method public instance void Cat([opt] string S,
          [opt] string sound) cil managed
          {
          .param [1] = "neko"
          .param [2] = "Nyao"
          // Code size 16 (0x10)
          .maxstack 8
          IL_0000: nop
          IL_0001: ldarg.1
          IL_0002: ldarg.2
          IL_0003: call string [mscorlib]System.String:: Concat(string,
          string)
          IL_0008: call void [mscorlib]System.Console: :WriteLine(stri ng)
          IL_000d: nop
          IL_000e: nop
          IL_000f: ret
          } // end of method Class1::Cat

          and an overload:
          ..method public instance void Cat(string S,
          bool B) cil managed
          {
          // Code size 22 (0x16)
          .maxstack 8
          IL_0000: nop
          IL_0001: ldarg.1
          IL_0002: ldarga.s B
          IL_0004: call instance string [mscorlib]System.Boolean: :ToString()
          IL_0009: call string [mscorlib]System.String:: Concat(string,
          string)
          IL_000e: call void [mscorlib]System.Console: :WriteLine(stri ng)
          IL_0013: nop
          IL_0014: nop
          IL_0015: ret
          } // end of method Class1::Cat

          which is the IL for the following two subs:
          Public Sub Cat(Optional ByVal S As String = "neko", Optional ByVal sound
          As String = "Nyao")
          Console.WriteLi ne(S + sound)
          End Sub

          Public Sub Cat(ByVal S As String, ByVal B As Boolean)
          Console.WriteLi ne(S + B.ToString())

          End Sub

          Optional parameters do not use overloading, they just expose a similar
          interface at the programming level, atleast in all cases I can find.

          [color=blue]
          > "Daniel O'Connell" <onyxkirx@--NOSPAM--comcast.net> wrote in message
          > news:dJYmb.3749 0$Tr4.73156@att bi_s03...[color=green]
          > >
          > > "William Ryan" <dotnetguru@nos pam.comcast.net > wrote in message
          > > news:uFOHjzAnDH A.3504@TK2MSFTN GP11.phx.gbl...[color=darkred]
          > > > According to C# Pro magazine, all the underlying code in VB.NET does[/color][/color]
          > when[color=green][color=darkred]
          > > > you use Optional Params is write the overload for you.... I've looked[/color][/color]
          > at[color=green][color=darkred]
          > > > the IL and couldn't verify it, but I'm far from an expert in IL.
          > > >[/color]
          > > Thats not true in any manner I've ever seen. I suspect that article was
          > > incorrect, ;). IL provides full support for declaring optional[/color][/color]
          arguments,[color=blue][color=green]
          > > with the OptionalAttribu te attribute and the .param attribute in IL,[/color]
          > however[color=green]
          > > it is just information, the language compiler is required to handle[/color][/color]
          using[color=blue][color=green]
          > > that information to use optional attributes.
          > >[color=darkred]
          > > > I agree too, optionals are eveil.[/color][/color][/color]


          Comment

          Working...