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 411 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.
  • 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
    Rocky Moore
    wrote on last edited by
    #92

    Yep, that would be handy!

    Rocky <>< Recent Blog Post: Netflix Gets Starz!

    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

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

      How about a way to check against all values in an array or enumerabale at once with perhaps the keyword 'any' like below.

      int[] supportedValues = new int[] { 3, 4, 5 }
      int x = 4;

      if (x == any supportedValues)
      {
      // Do something.
      }

      Instead of:

      int[] supportedValues = new int[] { 3, 4, 5 }
      int x = 4;
      bool xIsSupported = false;

      foreach (int value in supportedValues)
      {
      if (x == value)
      xIsSupported = true;
      }

      if (xIsSupported)
      {
      // Do something.
      }

      Good idea?

      B P S J 4 Replies 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
        Maximus014
        wrote on last edited by
        #94

        Can anyone say partial properties? Being able to add attributes to properties created in generated code would be awesome (using a the MetadataType approach is such an ugly hack). I would also love to be able to add extension methods to a static class. I know everyone has wanted to add some functionality to Membership or Math.

        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

          D Offline
          D Offline
          Dave Parker
          wrote on last edited by
          #95

          What's wrong with out parameters?

          1 Reply Last reply
          0
          • L Leslie Sanford

            Christian Graus wrote:

            I'd love to see a const keyword on parameters to methods

            Seems to me they could use the readonly keyword for this instead of introducing a new keyword. EDIT: :doh: const is already a keyword in C#. Shows you how rusty my C# is already... I'm not really up on compiler writing, so I'm not sure how hard this would be to implement in C#. The compiler would have to make sure that read-only properties/methods are called on readonly/const parameters. That may be nontrivial.

            D Offline
            D Offline
            Dave Parker
            wrote on last edited by
            #96

            Shame neither of them act as a kind of write-once property (other than readonly when set in a constructor) so you can't have constant DateTimes and things.

            1 Reply Last reply
            0
            • P Pawel Krakowiak

              MrPlankton wrote:

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

              What if there's not such method?

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

              You of course would write it, to handle that case.

              MrPlankton

              P 1 Reply Last reply
              0
              • L Lost User

                I believe this is a programming question! :mad:

                J Offline
                J Offline
                Jamie Nordmeyer
                wrote on last edited by
                #98

                No it's not. I'm not asking how to solve anything. Simply a feature ideas request. And since you're the only one so far to suggest this is a programming question, you're the only one who thinks so.

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

                1 Reply Last reply
                0
                • D Donkey Master

                  Christian Graus wrote:

                  I can use const to tell a user when they can trust my code not to change their stuff.

                  erm, I don't see how that would work. I thought that const was more of a promise to yourself, or to implementors, not to users. Nothing prevents you from calling methods and setting fields, right? Ok, let me start it again. What is the const keyword supposed to do in parameters that has an effect outside the method?

                  "Computer Science is no more about computers than astronomy is about telescopes." - Edsger Dijkstra

                  J Offline
                  J Offline
                  Jamie Nordmeyer
                  wrote on last edited by
                  #99

                  Here's an example of what I think he's saying:

                  public void DoSomething(const Employee emp)
                  {
                  emp.Age = 32; // This would not compile.
                  }

                  An object is passed by reference, so its properties are settable. You don't want to make the Age property read only, because normally, you want the consumer to be able to set it. But what if DoSomething was meant to be a final validation, and you didn't want anything in the object to change, because it could mess up state elsewhere? The const keyword would allow the developer to leave a property or field writable, but still be able to restrict when it could be written to.

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

                  D 1 Reply Last reply
                  0
                  • M MrPlankton

                    You of course would write it, to handle that case.

                    MrPlankton

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

                    MrPlankton wrote:

                    You of course would write it, to handle that case.

                    I thought so. :) Then it's the same as with the current lack of optional method arguments - you have to write overloads and people complain. Now you would have to write void methods...

                    M 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

                      H Offline
                      H Offline
                      Hooga Booga
                      wrote on last edited by
                      #101

                      Free beer!

                      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

                        U Offline
                        U Offline
                        User 3728064
                        wrote on last edited by
                        #102

                        really interesting!

                        1 Reply Last reply
                        0
                        • J Jamie Nordmeyer

                          here here!

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

                          G Offline
                          G Offline
                          Giampaolo Papotti
                          wrote on last edited by
                          #103

                          I strongly Agree! C# cut-offs from c++ were really too deep. cons keyword (both on parameters and members signatures) shoud be a MUST in any oo language. And what about the annoying lack of default in parameters? I'd like to see c# designers and gurus dealing with Office PIA... I'm sure they would have a private build of csc.exe with default parameters implementeed .... InvokeExcelStuff(theOnlyNeededParameter, null, null, null, null, null, null, null, null, null, null, null, null, null, null....)

                          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
                            pherschel
                            wrote on last edited by
                            #104

                            I'd like to see built in threading. Example: int x = CalcXDataValues() &; <- run as thread int y = CalcYDataValues() &; int z = x + y; // will not execute until x and y are set!

                            - Pete

                            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
                              Anubisasc
                              wrote on last edited by
                              #105

                              I would like to be able to do something like this:

                              const string[] constantArray = {
                              "String1",
                              "String2",
                              "String3"
                              };

                              Right now you can only create a static read only array.

                              1 Reply Last reply
                              0
                              • P Pawel Krakowiak

                                MrPlankton wrote:

                                You of course would write it, to handle that case.

                                I thought so. :) Then it's the same as with the current lack of optional method arguments - you have to write overloads and people complain. Now you would have to write void methods...

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

                                Well you could cast it to the method you want even if there is no left side argument. (int)functA("stuff"); I'm just saying having the return type as part of the signiture would be nice to have from time to time.

                                MrPlankton

                                P 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.

                                  G Offline
                                  G Offline
                                  grgran
                                  wrote on last edited by
                                  #107

                                  What would you expect 'const' to do? Would it just be the programmers promise not to change the contents of the object (generating an error if an assignment was attempted)? Would it also be able to determine if a method call on the object changed the state of the object and generate an error? If const is accepted as a parameter keyword should it also be accepted as a method modifier? How would optional parameters differ from the current params keyword?

                                  1 Reply Last reply
                                  0
                                  • M MrPlankton

                                    Well you could cast it to the method you want even if there is no left side argument. (int)functA("stuff"); I'm just saying having the return type as part of the signiture would be nice to have from time to time.

                                    MrPlankton

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

                                    MrPlankton wrote:

                                    I'm just saying having the return type as part of the signiture would be nice to have from time to time

                                    I know, I've been there myself. ;)

                                    1 Reply Last reply
                                    0
                                    • J Jamie Nordmeyer

                                      Here's an example of what I think he's saying:

                                      public void DoSomething(const Employee emp)
                                      {
                                      emp.Age = 32; // This would not compile.
                                      }

                                      An object is passed by reference, so its properties are settable. You don't want to make the Age property read only, because normally, you want the consumer to be able to set it. But what if DoSomething was meant to be a final validation, and you didn't want anything in the object to change, because it could mess up state elsewhere? The const keyword would allow the developer to leave a property or field writable, but still be able to restrict when it could be written to.

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

                                      D Offline
                                      D Offline
                                      Donkey Master
                                      wrote on last edited by
                                      #109

                                      Ok, I think I get it. So, I would be able to call methods and get properties and fields, but forbidden from setting fields and properties. Well, there are still the methods to change the data, so I guess that optimization-wise, this doesn't help. So, it's mostly syntactic sugar, a contract constraint. I'd put it in the same category as varargs, in terms of usefulness. You say that VB.NET has this feature today? How does it work when you import a VB.NET library to another language, like C#?

                                      "Computer Science is no more about computers than astronomy is about telescopes." - Edsger Dijkstra

                                      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

                                        G Offline
                                        G Offline
                                        grgran
                                        wrote on last edited by
                                        #110

                                        I'd like to see operator overloading supported in Interfaces, but this obvious has problems for languages that don't support op overloading. Here's what I'm thinking interface INumeric { ... overloads for +, -, /, *, remainder, (others) } class stats<T> where T:INumeric { ... methods to calculate staticial values on type T } This doesn't have to be done with interfaces (that just seems easiest). If all the numerics shared a common base class that would also be ok. I realize that this can be done with out op overloading (using only method calls), but I'd like to see it build-in so the standard types implement a basic set of operators, and users could implement their own (possibly) wacky types. That way the possibly complex methods used to calculate need only be written once. Consider, calculating Navier–Stokes equations over a large region, then as you drill down into a small region you find that you need more precision than the ~15 of doubles, so you write a high precision class that is much slower but provide the precision required. If there were a natural way to create such a class then it could just be plugged in via generics rather than requiring a bunch of complex equations to be rewritten for the new type or for method (rather than operator) expansion. Ok, that's enough wackiness for one day

                                        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

                                          G Offline
                                          G Offline
                                          Gonzalo Brusella
                                          wrote on last edited by
                                          #111

                                          Default initialization on auto-implemented properties!!

                                          I'm on a Fuzzy State: Between 0 an 1

                                          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