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 287 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.
  • S Shog9 0

    Sunny Ahuwanya wrote:

    Which do you think I'd choose?

    If you're a newbie programmer, then it doesn't matter - it'll suck. If you're just new to C#, then you'll want to play around with the tools, and it'll probably still suck. Once you've become comfortable and competent with both the language and C# in general, then you'll make a good choice given the requirements and constraints that apply. It might well be an extension method...

    ----

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

    S Offline
    S Offline
    Sunny Ahuwanya
    wrote on last edited by
    #135

    Shog9 wrote:

    If you're a newbie programmer, then it doesn't matter - it'll suck. If you're just new to C#, then you'll want to play around with the tools, and it'll probably still suck.

    Yeah, I guess it's always good to have newbies around to laugh at! :)

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

    1 Reply Last reply
    0
    • S shiftedbitmonkey

      harold aptroot wrote:

      Sure, edit the interface

      :laugh: :laugh: :laugh: And when its in a third party assembly? Are you proposing to decompile it through reflection, edit, then rebuild it to use just to omit the const? And if its obfuscated?

      I've heard more said about less.

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #136

      This is the const would be a bad idea.

      S 1 Reply Last reply
      0
      • H Hooga Booga

        Free beer!

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

        Only used beer is free. X|

        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
          #138

          And an ability to know what version is being used, to enable conditional compilation in a standard way:

          public static string F
          (

          **# if VERSION>=3.5
          this

          endif**

          string S
          

          )
          {
          ...
          }

          S 1 Reply Last reply
          0
          • L Lost User

            This is the const would be a bad idea.

            S Offline
            S Offline
            shiftedbitmonkey
            wrote on last edited by
            #139

            I disagree. This is the reason for const. To constrain an implementation. You think its a bad idea because you can't subvert it. Hmmm... while we're at it we might as well eliminate private and protected aspects of classes as well. Get rid of readonly and just let everything be completely open. And watch the bugs fly... Do you have a solid argument against const?

            I've heard more said about less.

            L 1 Reply Last reply
            0
            • A ASMiller

              How about the ability to partially set array values. For example, for an int array of length 10 with default values of 0..9 respectively, the following would be valid:

              myArray[3..5] = (-3, -4, -5);

              The contents would then be: 0, 1, 2, -3, -4, -5, 6, 7, 8, 9 Another idea is a composite Label (say Strings and Images). The display of CompositeLabel.Text would display a String followed by an Image then we could have things (using my mythical System.Text.SmileyFace namespace) like . . .

              myCompositeLabel.Text = "Hello, World " + System.Text.SmileyFace.BigGrin.ToImage();

              The display would then be: Hello, World :-D Anthony

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

              Unicode? RTF labels?

              1 Reply Last reply
              0
              • S S Senthil Kumar

                Sunny Ahuwanya wrote:

                There are so many things wrong with extension methods

                Care to list some of them? I get that they can pollute the list of methods in a class and can cause calls to unintended methods, what else do you find wrong?

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

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

                Confusion. a) People talk about them becoming members of the class, they do no such thing, they just look like it. b) Someone may ask "How do I do blah with X?" Someone else may answer "Just use X.blah()" without realizing that blah is an Extension Method (perhaps internal to the company or some third-party library that the asker doesn't have). The original asker will look in intellisense and maybe even check the documentation, but not find it. Extension Methods are user-hostile.

                1 Reply Last reply
                0
                • S shiftedbitmonkey

                  I disagree. This is the reason for const. To constrain an implementation. You think its a bad idea because you can't subvert it. Hmmm... while we're at it we might as well eliminate private and protected aspects of classes as well. Get rid of readonly and just let everything be completely open. And watch the bugs fly... Do you have a solid argument against const?

                  I've heard more said about less.

                  L Offline
                  L Offline
                  Lost User
                  wrote on last edited by
                  #142

                  shiftedbitmonkey wrote:

                  Do you have a solid argument against const?

                  Of course not, I just don't think that the reasons to include it are strong enough, so I argue ;)

                  1 Reply Last reply
                  0
                  • S Sunny Ahuwanya

                    Pawel Krakowiak wrote:

                    I think of them as of an improvement and use them. Smile

                    Can anyone explain to me how extension methods are an improvement? Besides helping to sell LINQ and encouraging programmers to write code in a non-portable, non object oriented manner, what is the point of extension methods?

                    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
                    #143

                    Sunny Ahuwanya wrote:

                    Can anyone explain to me how extension methods are an improvement?

                    They allow me to simply add new functionality to the existing classes, including Framework classes and I personally find them useful. I use them with Enums and String to provide some new functionality needed in a project. So their exact purpose is an improvement for me, there's nothing to add.

                    P 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

                      Y Offline
                      Y Offline
                      Yortw
                      wrote on last edited by
                      #144

                      1. Retry keyword, from VB.NET (structured error handling) 2. Dyanmic intefaces, from VB.NET 3. AppActivate function, from VB.NET 4. Non-beta version of the parallel task library 5. Better WPF designers 6. Better user experience when working on single code file shared between .NET Framework and .NET Compact Framework projects 7. Improved keyboard/focus and dynamic control creation support in .NET Compact Framework (support for ActiveControl, ControlAdded/Removed events etc). 8. Fix for the (very rare) bug caused by compiler optimisations on the String.IsNullOrEmpty function. 9. A version of the various TryParse functions that returns the default value for expected type, instead of returning true/false with an out parameter. 10. TryParse on System.Enum. Probably a lot of other stuff too, but that's all I can think of off the top of my head :-D Tuples would also be cool :cool:

                      J P 2 Replies Last reply
                      0
                      • P Pawel Krakowiak

                        Sunny Ahuwanya wrote:

                        Can anyone explain to me how extension methods are an improvement?

                        They allow me to simply add new functionality to the existing classes, including Framework classes and I personally find them useful. I use them with Enums and String to provide some new functionality needed in a project. So their exact purpose is an improvement for me, there's nothing to add.

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

                        Pawel Krakowiak wrote:

                        add new functionality to the existing classes

                        They do nothing of the sort!

                        J P 2 Replies Last reply
                        0
                        • B bVagadishnu

                          foreach (int value in supportedValues) { if (x == value) { xIsSupported = true; break; //why keep on when you are done? :confused: } }

                          S Offline
                          S Offline
                          SlingBlade
                          wrote on last edited by
                          #146

                          lol, it was late and I definately could have used a break, so I just didn't bother with the break. Or should I say didn't bother editing the post and fixing the bug when I realized I had forgotten to throw in the break. All the more reason the change would be so useful. Not only could it make for less coding, less bugs too.

                          1 Reply Last reply
                          0
                          • P PIEBALDconsult

                            Use a HashSet instead of an array.

                            S Offline
                            S Offline
                            SlingBlade
                            wrote on last edited by
                            #147

                            I don't want to use a HashSet. The whole point of the change suggestion is flexibility to use with any type of enumerable without having to write the code to iterate through it or convert it. That and a HashSet would only be able to handle the == or != operators. What if I want to use >, <, <= or >=?

                            1 Reply Last reply
                            0
                            • J Jamie Nordmeyer

                              here here!

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

                              A Offline
                              A Offline
                              andy_p
                              wrote on last edited by
                              #148

                              hear, hear! I had heard that proper run-time const support in the clr was far too hard or expensive, and providing a weak const keyword in c# (like c++ has got) without properly enforcing it in the clr would just be misleading. Shame though; I would have liked proper const guarantees in the clr.

                              1 Reply Last reply
                              0
                              • L Leslie Sanford

                                harold aptroot wrote:

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

                                Well, that's kind of the point. You want to limit the usage of const parameters to minimize side-effects.

                                A Offline
                                A Offline
                                andy_p
                                wrote on last edited by
                                #149

                                Leslie Sanford wrote:

                                You want to limit the usage of const parameters to minimize side-effects.

                                Shouldn't it be "You want to use the limit of const parameters to minimize side-effects"? :)

                                1 Reply Last reply
                                0
                                • P Pawel Krakowiak

                                  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 Offline
                                  A Offline
                                  andy_p
                                  wrote on last edited by
                                  #150

                                  maybe another advantage is that loads of defaulted parameters would slow a simple call down, but using overloaded functions it would not have to push all those unused parameters onto the stack, so it would go faster.

                                  1 Reply Last reply
                                  0
                                  • P PIEBALDconsult

                                    Jamie Nordmeyer wrote:

                                    C# 4.0

                                    I haven't heard anything about it.

                                    Jamie Nordmeyer wrote:

                                    return min, max;

                                    That syntax wouldn't be a good choice, because of the comma operator. I would just return an array of int. Though the only place I do that is a routine that parses a string to get a latitude and longitude (doubles in this case).

                                    R Offline
                                    R Offline
                                    Ribose
                                    wrote on last edited by
                                    #151

                                    PIEBALDconsult wrote:

                                    I would just return an array of int. Though the only place I do that is a routine that parses a string to get a latitude and longitude (doubles in this case).

                                    I would return a System.Drawing.PointF for latitude/longitude values, or if I needed lat/long minutes and seconds, I would make a struct for it. :)

                                    ~Ribose

                                    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

                                      A Offline
                                      A Offline
                                      andy_p
                                      wrote on last edited by
                                      #152

                                      I'd like to see member variables treated as if they were in a class-lifetime 'using' statement. I miss the deterministic destructor from c++, but this would at least allow me to put the class in a using statement and have its member variables' dispose methods called implicitly.

                                      A 1 Reply Last reply
                                      0
                                      • A andy_p

                                        I'd like to see member variables treated as if they were in a class-lifetime 'using' statement. I miss the deterministic destructor from c++, but this would at least allow me to put the class in a using statement and have its member variables' dispose methods called implicitly.

                                        A Offline
                                        A Offline
                                        andy_p
                                        wrote on last edited by
                                        #153

                                        I guess I just want the default implementation of Dispose() to call Dispose() on all the member variables.

                                        1 Reply Last reply
                                        0
                                        • S S Senthil Kumar

                                          Let's say you are using a library with the following code

                                          // Assembly SomeLib.dll

                                          class C
                                          {
                                          void someMethod() const {...}
                                          }

                                          and the code using it looks like this

                                          // Assembly App.exe

                                          void usingMethod(const C obj)
                                          {
                                          obj.someMethod(); // ok, because someMethod is const
                                          }

                                          Now let's say a new version of SomeLib.dll comes out and in that version, someMethod() becomes non-const. With C++, App.exe would require recompiling with the modified header file, and the compiler would be able to flag the error in usingMethod (non const method call on a const object). With .NET and binary compatibility, there's no recompiling necessary - you just drop in the new DLL and now the const guarantee is broken. It would be a silent breaking change, 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
                                          #154

                                          Thanks for the explanation, but how would you implement a runtime check? And what would it do - throw an exception that the called code has changed the object despite its (earlier) promise not to?

                                          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