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. C# 4.0

C# 4.0

Scheduled Pinned Locked Moved The Lounge
csharpquestiondiscussionannouncement
233 Posts 75 Posters 460 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.
  • L Lost User

    Then so be it, in this case you would simply remove the "const" if it were there, meaning that it shouldn't really have been there to start with

    C Offline
    C Offline
    Christian Graus
    wrote on last edited by
    #55

    Do you never write code that other people will use ?

    Christian Graus No longer a Microsoft MVP, but still happy to answer your questions.

    1 Reply Last reply
    0
    • C Christian Graus

      I'd love to see a const keyword on parameters to methods, and optional parameters. Both of which seem simple enough.

      Christian Graus No longer a Microsoft MVP, but still happy to answer your questions.

      A Offline
      A Offline
      Ashley van Gerven
      wrote on last edited by
      #56

      BTW - am I correct in saying you can only apply const to value types? That's the behaviour I seem to get with C# 3.0

      "For fifty bucks I'd put my face in their soup and blow." - George Costanza

      1 Reply Last reply
      0
      • M Mladen Jankovic

        Yeah, but what method should be called if I want to ignore return value? 1. int i = functA("a"); // ok int functA(string) is called 2. string s = functA("a"); // ok string functA(string) is called 3. functA("a"); // wtf?

        [Genetic Algorithm Library]

        M Offline
        M Offline
        MrPlankton
        wrote on last edited by
        #57

        well then how about a void functA("a"); one would assume that this default case would be anticipated by programmer, but failing that; the syntax could be; (cast)functA("a"); and that would work to even though there is no left param; but compiler would flag functA("a"); with a warning. Would that work for you? What would you like to see?

        MrPlankton

        P 1 Reply Last reply
        0
        • S Shog9 0

          I was wishing for such a thing just yesterday. Ended up using an array, but the calling code is much uglier for having to unpack it. Actually, what would be great would be something like the destructuring assignment syntax recently added to JavaScript. Imagine being able to do this:

          double w;
          double h;
          double d;
          ...

          [w,h,d] = CalculateDimensions(...);

          :-D

          ----

          You're right. These facts that you've laid out totally contradict the wild ramblings that I pulled off the back of cornflakes packets.

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

          and return [w,h,d] ? or return {w,h,d} ?

          S 1 Reply Last reply
          0
          • S Sunny Ahuwanya

            I'd like them to include a compiler switch to treat extension methods as errors. I'd also like them to place a "feature freeze" on the language. A good programming language need not be updated every three years.

            Sunny Ahuwanya "The beauty of the desert is that it hides a well somewhere" -- Antoine de Saint Exupéry

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

            Oh, well then... Treat the using directive as an error. While you're at it, require full attribute names.

            S 1 Reply Last reply
            0
            • J Jamie Nordmeyer

              So now that C# 4.0 is being talked about, I was wondering what people thought would be good additions to the language. Sorry if this is a repost, but I went through several pages, and didn't see anything, so... What I'd frankly love to see would be tuples. Rather than having to use multiple 'out' parameters, you'd just return multiple values:

              public int,int MinMax(int[] numbers)
              {
              int min, max;
              // Code to calculate min/max

              return min, max;
              }

              What do you think? What would be good for the next version?

              Kyosa Jamie Nordmeyer - Taekwondo Yi (2nd) Dan Portland, Oregon, USA

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

              Oh, another one; the is operator needs a complement: !is isnt aint !( x is someclass ) is so clunky!

              1 Reply Last reply
              0
              • P PIEBALDconsult

                and return [w,h,d] ? or return {w,h,d} ?

                S Offline
                S Offline
                Shog9 0
                wrote on last edited by
                #61

                PIEBALDconsult wrote:

                and return [w,h,d] ?

                Yeah, keep it distinct from blocks, initializers, etc.

                ----

                You're right. These facts that you've laid out totally contradict the wild ramblings that I pulled off the back of cornflakes packets.

                J 1 Reply Last reply
                0
                • M Member 96

                  I'd really really really like to see absolutely no changes whatsoever. Seriously.


                  "It's so simple to be wise. Just think of something stupid to say and then don't say it." -Sam Levenson

                  P Offline
                  P Offline
                  Paul Selormey
                  wrote on last edited by
                  #62

                  Thank you. Best regards, Paul.

                  Jesus Christ is LOVE! Please tell somebody.

                  1 Reply Last reply
                  0
                  • N Nemanja Trifunovic

                    Christian Graus wrote:

                    optional parameters

                    Mixing optional parameters and overloads can lead to pretty bad mess.

                    Programming Blog utf8-cpp

                    Steve EcholsS Offline
                    Steve EcholsS Offline
                    Steve Echols
                    wrote on last edited by
                    #63

                    I've never had a problem with them in C++, you just have to design it so there's no ambiguity. I think optionals are much cleaner than writing tons of overloads that end up calling the base function with default values. Here's a question that you all might know. Given: void Foo() { Foo(0); } void Foo(x) { Foo(x, 0) } void Foo(x, y) { } Does calling Foo() make 3 function calls, or does the compiler optimize this in any way? If you're simulating optional parameters with 10 overloads, this could get expensive real fast! The alternative is to have every overload call the base function, specifying all the parameters. This would reduce it to 2 function calls. void Foo() { Foo(0, 0); } void Foo(x) { Foo(x, 0) } void Foo(x, y) { } Just rambling now....


                    - S 50 cups of coffee and you know it's on! A post a day, keeps the white coats away!

                    • S
                      50 cups of coffee and you know it's on!
                      Code, follow, or get out of the way.
                    1 Reply Last reply
                    0
                    • C Christian Graus

                      I'd love to see a const keyword on parameters to methods, and optional parameters. Both of which seem simple enough.

                      Christian Graus No longer a Microsoft MVP, but still happy to answer your questions.

                      S Offline
                      S Offline
                      S Senthil Kumar
                      wrote on last edited by
                      #64

                      Christian Graus wrote:

                      const keyword on parameters to methods

                      But how would the compiler verify the "constness" of methods that you call on a const object? The methods themselves would have to be declared const, just like in C++. Everything, including the BCL, will need to change for that. There's also the versioning problem. In C++, if a library changes, you are forced to recompile with the modified header files. There's no such need in .NET, so if a method declared const in v1 of the library became non const in v2, the "constness" guarantee will get broken (unless there is a runtime check).

                      Regards Senthil [MVP - Visual C#] _____________________________ My Home Page |My Blog | My Articles | My Flickr | WinMacro

                      V 1 Reply Last reply
                      0
                      • C Christian Graus

                        I'd love to see a const keyword on parameters to methods, and optional parameters. Both of which seem simple enough.

                        Christian Graus No longer a Microsoft MVP, but still happy to answer your questions.

                        P Offline
                        P Offline
                        Pawel Krakowiak
                        wrote on last edited by
                        #65

                        As for the optional parameters, they say that method overloads work better in that respect. I got used to it and don't complain. Maybe one advantage (trying to agree with MS) I can see is that when you debug your C# code the debugger (Call Stack) will show you which overload was called exactly, while it may not be apparent if a default parameter value was used...

                        A 1 Reply Last reply
                        0
                        • M MrPlankton

                          It's been awhile since I did any c++, but I believe you would get a compile warning with Borlands old c++ compiler and then it would take it's best guess. Casting the function call would make the compiler happy. They could do the same with next version c#.

                          MrPlankton

                          P Offline
                          P Offline
                          Pawel Krakowiak
                          wrote on last edited by
                          #66

                          MrPlankton wrote:

                          It's been awhile since I did any c++, but I believe you would get a compile warning with Borlands old c++ compiler and then it would take it's best guess

                          I'd rather not see it. I treat compiler warnings as errors, but from time to time I have to work with people who do stuff like try..catch with the general exception and don't even log the exception message. :( The compiler cries of course but no one pays attention. *sigh* That proposed feature is very interesting, but I'm afraid of it. ;)

                          1 Reply Last reply
                          0
                          • M MrPlankton

                            well then how about a void functA("a"); one would assume that this default case would be anticipated by programmer, but failing that; the syntax could be; (cast)functA("a"); and that would work to even though there is no left param; but compiler would flag functA("a"); with a warning. Would that work for you? What would you like to see?

                            MrPlankton

                            P Offline
                            P Offline
                            Pawel Krakowiak
                            wrote on last edited by
                            #67

                            MrPlankton wrote:

                            well then how about a void functA("a");

                            What if there's not such method?

                            M 1 Reply Last reply
                            0
                            • S Sunny Ahuwanya

                              Me too. I think they already degraded the language in C# 3 by adding extension methods and partial methods just to sell LINQ.

                              Sunny Ahuwanya "The beauty of the desert is that it hides a well somewhere" -- Antoine de Saint Exupéry

                              P Offline
                              P Offline
                              Pawel Krakowiak
                              wrote on last edited by
                              #68

                              Sunny Ahuwanya wrote:

                              I think they already degraded the language in C# 3 by adding extension methods

                              I think of them as of an improvement and use them. :)

                              S 1 Reply Last reply
                              0
                              • J Jamie Nordmeyer

                                So now that C# 4.0 is being talked about, I was wondering what people thought would be good additions to the language. Sorry if this is a repost, but I went through several pages, and didn't see anything, so... What I'd frankly love to see would be tuples. Rather than having to use multiple 'out' parameters, you'd just return multiple values:

                                public int,int MinMax(int[] numbers)
                                {
                                int min, max;
                                // Code to calculate min/max

                                return min, max;
                                }

                                What do you think? What would be good for the next version?

                                Kyosa Jamie Nordmeyer - Taekwondo Yi (2nd) Dan Portland, Oregon, USA

                                R Offline
                                R Offline
                                Rei Miyasaka
                                wrote on last edited by
                                #69

                                Static verification would be awesome. Contracts[^] would be nice too if they could get some of those features in without making too much of a mess. For instance, Spec# will throw a compile-time error (and squiggly underline in Visual Studio) with this code:

                                public float Divide(float x, float y)
                                {
                                return x / y;
                                }

                                But this would be valid:

                                public float Divide(float x, float y)
                                requires y != 0
                                {
                                return x / y;
                                }

                                As would this:

                                public float Divide(float x, float y)
                                {
                                if(y == 0)
                                throw new ArgumentException("y");
                                return x / y;
                                }

                                J 1 Reply Last reply
                                0
                                • L Lost User

                                  Why const? What will it even do besides limit the programmer in the usage of said parameters?

                                  I Offline
                                  I Offline
                                  Ian Good
                                  wrote on last edited by
                                  #70

                                  const parameters would be very nice, it's a very clear way to show me that my object has not been changed after the function to which I passed it returns

                                  1 Reply Last reply
                                  0
                                  • J Jamie Nordmeyer

                                    So now that C# 4.0 is being talked about, I was wondering what people thought would be good additions to the language. Sorry if this is a repost, but I went through several pages, and didn't see anything, so... What I'd frankly love to see would be tuples. Rather than having to use multiple 'out' parameters, you'd just return multiple values:

                                    public int,int MinMax(int[] numbers)
                                    {
                                    int min, max;
                                    // Code to calculate min/max

                                    return min, max;
                                    }

                                    What do you think? What would be good for the next version?

                                    Kyosa Jamie Nordmeyer - Taekwondo Yi (2nd) Dan Portland, Oregon, USA

                                    M Offline
                                    M Offline
                                    MukeshKAgarwal
                                    wrote on last edited by
                                    #71

                                    do anybody suggest me any gud article on 4.0 And what is the raod map of 4.0

                                    1 Reply Last reply
                                    0
                                    • M Mladen Jankovic

                                      1. one of main differences between high-level languages and assembly language is that they introduces many ways to limit the programmer 2. const keyword is not only a limitation it is also a reminder for you and for others that there is a reason why something should not be changed. And const is certainly a better solution than running around the office saying 'promise me that you will not try to change data returned by SomeLongAndCrypticFunctionName'

                                      [Genetic Algorithm Library]

                                      R Offline
                                      R Offline
                                      rastaVnuce
                                      wrote on last edited by
                                      #72

                                      Mladen Jankovic wrote:

                                      And const is certainly a better solution than running around the office saying 'promise me that you will not try to change data returned by SomeLongAndCrypticFunctionName'

                                      Yes, but running is good for you! :laugh:

                                      To hell with circumstances; I create opportunities.

                                      1 Reply Last reply
                                      0
                                      • C Christian Graus

                                        I'd love to see a const keyword on parameters to methods, and optional parameters. Both of which seem simple enough.

                                        Christian Graus No longer a Microsoft MVP, but still happy to answer your questions.

                                        V Offline
                                        V Offline
                                        Vikram A Punathambekar
                                        wrote on last edited by
                                        #73

                                        I am astounded they don't support const parameters yet. Naturally, if they support const parameters, they will almost certainly have to support const methods. I think const parameters are one of the best things about C++ that got dropped out in C#.

                                        Cheers, Vıkram.


                                        "You idiot British surprise me that your generators which grew up after Mid 50s had no brain at all." - Adnan Siddiqi.

                                        1 Reply Last reply
                                        0
                                        • S S Senthil Kumar

                                          Christian Graus wrote:

                                          const keyword on parameters to methods

                                          But how would the compiler verify the "constness" of methods that you call on a const object? The methods themselves would have to be declared const, just like in C++. Everything, including the BCL, will need to change for that. There's also the versioning problem. In C++, if a library changes, you are forced to recompile with the modified header files. There's no such need in .NET, so if a method declared const in v1 of the library became non const in v2, the "constness" guarantee will get broken (unless there is a runtime check).

                                          Regards Senthil [MVP - Visual C#] _____________________________ My Home Page |My Blog | My Articles | My Flickr | WinMacro

                                          V Offline
                                          V Offline
                                          Vikram A Punathambekar
                                          wrote on last edited by
                                          #74

                                          S. Senthil Kumar wrote:

                                          The methods themselves would have to be declared const, just like in C++.

                                          Yeah, I wrote that myself, without reading your post. :doh:

                                          S. Senthil Kumar wrote:

                                          if a method declared const in v1 of the library became non const in v2, the "constness" guarantee will get broken (unless there is a runtime check).

                                          I'm not sure I understand, could you please explain?

                                          Cheers, Vıkram.


                                          "You idiot British surprise me that your generators which grew up after Mid 50s had no brain at all." - Adnan Siddiqi.

                                          S 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