Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. The Lounge
  3. I wish C# 3.0 had optional parameters

I wish C# 3.0 had optional parameters

Scheduled Pinned Locked Moved The Lounge
csharpdotnetcomgraphics
36 Posts 14 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Keith Barrow

    I've done what I usually do, used ".net" interchangeably with "c#" - stupid I know, but I keep doing it anyway , I can be quite wooley-minded at times. :(

    Sort of a cross between Lawrence of Arabia and Dilbert.[^]
    -Or-A Dead ringer for Kate Winslett[^]

    P Offline
    P Offline
    PIEBALDconsult
    wrote on last edited by
    #27

    Thought so, but when I see a chain I yank it -- pedantry never sleeps. :-D

    K 1 Reply Last reply
    0
    • C Cesar de Souza

      ... it is like the 218283th overload I am writing, and it only grows exponentially! :( Oh, and for the down-voters - this was meant to be a joke :doh:

      Interested in Machine Learning in .NET? Check the Accord.NET Framework. See also Handwriting Recognition Revisited: Kernel Support Vector Machines

      S Offline
      S Offline
      Super Lloyd
      wrote on last edited by
      #28

      It does! It's a compiler thing.. the .NET4 compiler makes optional parameter in C#3 code. I have VS2010, and our project is still ( :(( ) in .NET3.5, but I use optional parameter all the time, thanks to VS2010, SDK .NET4!!! :)

      A train station is where the train stops. A bus station is where the bus stops. On my desk, I have a work station.... _________________________________________________________ My programs never have bugs, they just develop random features.

      C 1 Reply Last reply
      0
      • P PIEBALDconsult

        Thought so, but when I see a chain I yank it -- pedantry never sleeps. :-D

        K Offline
        K Offline
        Keith Barrow
        wrote on last edited by
        #29

        PIEBALDconsult wrote:

        pedantry never sleeps.

        LOL!

        Sort of a cross between Lawrence of Arabia and Dilbert.[^]
        -Or-A Dead ringer for Kate Winslett[^]

        1 Reply Last reply
        0
        • S Super Lloyd

          It does! It's a compiler thing.. the .NET4 compiler makes optional parameter in C#3 code. I have VS2010, and our project is still ( :(( ) in .NET3.5, but I use optional parameter all the time, thanks to VS2010, SDK .NET4!!! :)

          A train station is where the train stops. A bus station is where the bus stops. On my desk, I have a work station.... _________________________________________________________ My programs never have bugs, they just develop random features.

          C Offline
          C Offline
          Cesar de Souza
          wrote on last edited by
          #30

          Yeah, it works under VS2010. But have you tried calling those methods under VS2008 and not specifying the optional parameters? As far as I could tell, the compiler does not create overloads, it uses a [Optional] attribute to mark those parameters. It compiles to .NET 3.5 because support for Optional parameters has been there from a long time.

          Interested in Machine Learning in .NET? Check the Accord.NET Framework. See also Handwriting Recognition Revisited: Kernel Support Vector Machines

          1 Reply Last reply
          0
          • C Cesar de Souza

            ... it is like the 218283th overload I am writing, and it only grows exponentially! :( Oh, and for the down-voters - this was meant to be a joke :doh:

            Interested in Machine Learning in .NET? Check the Accord.NET Framework. See also Handwriting Recognition Revisited: Kernel Support Vector Machines

            C Offline
            C Offline
            Cesar de Souza
            wrote on last edited by
            #31

            by the way - this was meant to be a joke :doh:

            Interested in Machine Learning in .NET? Check the Accord.NET Framework. See also Handwriting Recognition Revisited: Kernel Support Vector Machines

            1 Reply Last reply
            0
            • K Keith Barrow

              I'm going to throw this out to you out as a suggestion: Just upgrade to .net 4.0 if possible, you should have unit tests in place to see if anything breaks :-), if everything is OK (and you don't have any weird user-machine requirements) then upgrade. I withdrew from an interview (the only time I have ever done this) about a year and a half ago because they were using .net 2.0 and had no plans to updgrade. They said that they understood that developers always wanted to "play with new toys" I challenged this (politely of course), I'd already shipped .net 3.5 stuff and the improvements to over .net 2.0 were compelling: LINQ, performance, WCF, WPF etc, not just "toys". I also pointed out that any decent dev will want to move onto the new platorm ASAP (OK, the "P" is important) and you [presumably] want to hire decent dev. I spoke to the two devs on the interview panel, one wasn't interested in learning new stuff, the other just seemed hidebound by corporate sclerosis and managerial interference. The stupid thing was this was a "startup" but under an umbrella company (itself not huge) that insisted on .net 2.0. I think I even said the company won't remain competative in the market for more than a few years.

              Sort of a cross between Lawrence of Arabia and Dilbert.[^]
              -Or-A Dead ringer for Kate Winslett[^]

              D Offline
              D Offline
              Dan Neely
              wrote on last edited by
              #32

              I don't want to write 2.0/etc code in 2010. I want to write 4.0 code in 2008 because it's actually stable. 2010 falls over as readily as a nonspinning top balanced on its point. Barring a stability service pack, I'd like to keep any new projects in 2008. X|

              3x12=36 2x12=24 1x12=12 0x12=18

              1 Reply Last reply
              0
              • C Cesar de Souza

                I am grateful for the link - I wasn't aware of some of the functions mentioned there. Thanks :thumbsup:

                Interested in Machine Learning in .NET? Check the Accord.NET Framework. See also Handwriting Recognition Revisited: Kernel Support Vector Machines

                B Offline
                B Offline
                BC3Tech
                wrote on last edited by
                #33

                seems like if _arglist fits your bill, so would "params object[] variableName" B

                1 Reply Last reply
                0
                • C Cesar de Souza

                  ... it is like the 218283th overload I am writing, and it only grows exponentially! :( Oh, and for the down-voters - this was meant to be a joke :doh:

                  Interested in Machine Learning in .NET? Check the Accord.NET Framework. See also Handwriting Recognition Revisited: Kernel Support Vector Machines

                  M Offline
                  M Offline
                  Matthew Dennis
                  wrote on last edited by
                  #34

                  The need for many 'optional' parameters and method overloads is usually a good indicator that your class and/or method is not following the Single Responsibility Principle. You should look a refactoring so that you only need two parameters (three if you realy have to). I think you will end up with better code with a lot less if and switch statements.

                  C 1 Reply Last reply
                  0
                  • M Matthew Dennis

                    The need for many 'optional' parameters and method overloads is usually a good indicator that your class and/or method is not following the Single Responsibility Principle. You should look a refactoring so that you only need two parameters (three if you realy have to). I think you will end up with better code with a lot less if and switch statements.

                    C Offline
                    C Offline
                    Cesar de Souza
                    wrote on last edited by
                    #35

                    Thanks Matthew. Indeed, having too many overloads may be a good indicator for refactoring. My original posting was an attempt of a joke, but the discussion here did arise some interesting questions about when to use several method overloads and/or optional parameters. I am specifically thinking about situations like in the case of MessageBox.Show(), which has about 20 overloads. Wouldn't this be a perfect example of when optional parameters would be useful?

                    Interested in Machine Learning in .NET? Check the Accord.NET Framework. See also Handwriting Recognition Revisited: Kernel Support Vector Machines

                    M 1 Reply Last reply
                    0
                    • C Cesar de Souza

                      Thanks Matthew. Indeed, having too many overloads may be a good indicator for refactoring. My original posting was an attempt of a joke, but the discussion here did arise some interesting questions about when to use several method overloads and/or optional parameters. I am specifically thinking about situations like in the case of MessageBox.Show(), which has about 20 overloads. Wouldn't this be a perfect example of when optional parameters would be useful?

                      Interested in Machine Learning in .NET? Check the Accord.NET Framework. See also Handwriting Recognition Revisited: Kernel Support Vector Machines

                      M Offline
                      M Offline
                      Matthew Dennis
                      wrote on last edited by
                      #36

                      What is show is that the MessageBox.Show method probably needs fewer overloads and to be passed an object that defines the values for the various options.

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups