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# 6 Features

C# 6 Features

Scheduled Pinned Locked Moved The Lounge
csharpphpcomquestion
14 Posts 7 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.
  • L Offline
    L Offline
    Lost User
    wrote on last edited by
    #1

    This thread[^] is sparking some debate in the new section, but we should probably do that here, right? So, the first thing is notice is that I find myself really hating string interpolation with a passion. Anything in a string should be string, not some sneaky variable name. C# is not PHP. Await in catch/finally sounds great though. In the past I've needed ugly hacks to approximate that.

    I F D F 4 Replies Last reply
    0
    • L Lost User

      This thread[^] is sparking some debate in the new section, but we should probably do that here, right? So, the first thing is notice is that I find myself really hating string interpolation with a passion. Anything in a string should be string, not some sneaky variable name. C# is not PHP. Await in catch/finally sounds great though. In the past I've needed ugly hacks to approximate that.

      I Offline
      I Offline
      Ian Shlasko
      wrote on last edited by
      #2

      Well, those strings aren't normal strings when you add the $ prefix... It's syntactic sugar for a more readable string.format. Haven't used the async/await stuff yet, as I'm still stuck on VS2010 / .NET 4.0 (Sucks to be the only .NET programmer in a Java shop)... Some of the changes look useful though... * Static initializers - Very situational, but would help with some of the legacy code I support * Auto property initializers - Nice * Dictionary initializers - Uh, ok... But the old method was good enough * String interpolation - Sure * nameOf() - Somewhat useful * Expression-bodied functions - Um, ok... So it's a Func<>, but it looks almost like a method... Meh * Exception filters - I suppose... But imagine how badly this will be abused by horrible coders * Await in try/catch - As above, haven't used async/await yet, so dunno * Null conditional - YES! So many null checks that all do the same damn thing...

      Proud to have finally moved to the A-Ark. Which one are you in?
      Author of the Guardians Saga (Sci-Fi/Fantasy novels)

      Richard DeemingR 1 Reply Last reply
      0
      • L Lost User

        This thread[^] is sparking some debate in the new section, but we should probably do that here, right? So, the first thing is notice is that I find myself really hating string interpolation with a passion. Anything in a string should be string, not some sneaky variable name. C# is not PHP. Await in catch/finally sounds great though. In the past I've needed ugly hacks to approximate that.

        F Offline
        F Offline
        F ES Sitecore
        wrote on last edited by
        #3

        The null check will be dead useful, not sure if I'd adopt much of the other stuff. But then I still for "foreach" like the dinosaur I am.

        P 1 Reply Last reply
        0
        • I Ian Shlasko

          Well, those strings aren't normal strings when you add the $ prefix... It's syntactic sugar for a more readable string.format. Haven't used the async/await stuff yet, as I'm still stuck on VS2010 / .NET 4.0 (Sucks to be the only .NET programmer in a Java shop)... Some of the changes look useful though... * Static initializers - Very situational, but would help with some of the legacy code I support * Auto property initializers - Nice * Dictionary initializers - Uh, ok... But the old method was good enough * String interpolation - Sure * nameOf() - Somewhat useful * Expression-bodied functions - Um, ok... So it's a Func<>, but it looks almost like a method... Meh * Exception filters - I suppose... But imagine how badly this will be abused by horrible coders * Await in try/catch - As above, haven't used async/await yet, so dunno * Null conditional - YES! So many null checks that all do the same damn thing...

          Proud to have finally moved to the A-Ark. Which one are you in?
          Author of the Guardians Saga (Sci-Fi/Fantasy novels)

          Richard DeemingR Offline
          Richard DeemingR Offline
          Richard Deeming
          wrote on last edited by
          #4

          Ian Shlasko wrote:

          Expression-bodied functions - Um, ok... So it's a Func<>, but it looks almost like a method... Meh

          Almost - it's a regular method that looks like a lambda function. :)


          "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

          "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

          1 Reply Last reply
          0
          • L Lost User

            This thread[^] is sparking some debate in the new section, but we should probably do that here, right? So, the first thing is notice is that I find myself really hating string interpolation with a passion. Anything in a string should be string, not some sneaky variable name. C# is not PHP. Await in catch/finally sounds great though. In the past I've needed ugly hacks to approximate that.

            D Offline
            D Offline
            Dennis_E
            wrote on last edited by
            #5

            * Static initializers - I can't imagine using it for Console.WriteLine or something (we always type cw{Tab} anyway, right?) And there's a problem that some methods don't have an intuitive name without the class name, like Tuple.Create. But I like that I can now import extension methods from classes instead of namespaces. * Auto property initializers - Very neat. Should have been there from the beginning. * Dictionary initializers - I guess it's a more intuitive way of writing this particular code but was it absolutely necessary? No. Now we just have 2 slightly different ways of writing the same thing. * String interpolation - I agree it doesn't look pretty, but the old way ({0},{1},{2},etc) didn't look pretty either. * nameof() - Very small feature, but it makes sense to use it everywhere you can. * Expression-bodied members - I think this is a confusing feature. It doesn't even save that much typing. Methods don't look like methods anymore and properties no longer have a 'get' keyword. * Exception filters - Should be useful on rare occasions, but will be abused more often. * Await in catch/finally - Without it, async/await is an incomplete feature, so it should be there, but I don't expect to use it much. * Null conditional - This takes away a lot of ugly, boring, annoying code. Very nice. But it will make C# more cryptic for novice programmers.

            1 Reply Last reply
            0
            • F F ES Sitecore

              The null check will be dead useful, not sure if I'd adopt much of the other stuff. But then I still for "foreach" like the dinosaur I am.

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

              F-ES Sitecore wrote:

              I still for "foreach" like the dinosaur I am

              No! Use for whenever you can! Avoid foreach and its ilk unless it's the only thing that will work.

              L 1 Reply Last reply
              0
              • P PIEBALDconsult

                F-ES Sitecore wrote:

                I still for "foreach" like the dinosaur I am

                No! Use for whenever you can! Avoid foreach and its ilk unless it's the only thing that will work.

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

                What's wrong with foreach?

                P F 2 Replies Last reply
                0
                • L Lost User

                  This thread[^] is sparking some debate in the new section, but we should probably do that here, right? So, the first thing is notice is that I find myself really hating string interpolation with a passion. Anything in a string should be string, not some sneaky variable name. C# is not PHP. Await in catch/finally sounds great though. In the past I've needed ugly hacks to approximate that.

                  F Offline
                  F Offline
                  FIorian Schneidereit
                  wrote on last edited by
                  #8

                  Static Using Syntax - I think its usefulness really depends on the use-case. If you have a class that makes heavy use of Console or static members in Math, it can be beneficial; otherwise, things might get weird easily. Auto-Property Initializers - I don't use much of the syntactic sugar since C# 3.0, but it's good for people who like it because this feature makes auto properties complete. Dictionary Initializers - I don't really care. String Interpolation - Looks better than the String.Format syntax but can be problematic when it comes to localization. Still, I like it a lot. nameof() Expression - A small but very welcome feature, I use it everywhere I can. This one really shines in Roslyn-based refactorings. Expression-bodied Methods and Properties - I don't really care, not too beneficial. Exception Filters - I guess this one has been supported by the CLR ever since, now it is exposed by C#. Can be useful, but like many others I see a large abuse vector. Await in Catch/Finally - I don't do much async stuff, but it makes the whole feature complete. Null-Conditional Operator - Surely a nice to have shortcut, but it makes the code harder to read, especially for people who are not used to it. I think this version of C# brought some very welcome additions, but it's also beginning to get seriously bloated. Too much choices and syntactic sugar can become problematic and a mess if you're working on projects with different kinds of coding guidelines.

                  1 Reply Last reply
                  0
                  • L Lost User

                    What's wrong with foreach?

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

                    Not as efficient as a for for the same task.

                    L 1 Reply Last reply
                    0
                    • P PIEBALDconsult

                      Not as efficient as a for for the same task.

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

                      OK, but that may be a bit outdated - for example, the difference between private static int test1(int[] ar) { int sum = 0; foreach (var i in ar) { sum += i; } return sum; } and private static int test2(int[] ar) { int sum = 0; for (int i = 0; i < ar.Length; i++) { sum += ar[i]; } return sum; } Is .. not much. The loop bodies are

                      _loop1:
                      mov eax,dword ptr [rdx+r9+10h]
                      add ecx,eax
                      inc r8d
                      add r9,4
                      cmp r8d,r10d
                      jl _loop1

                      _loop2:
                      mov eax,dword ptr [rdx+r9+10h]
                      add ecx,eax
                      inc r8d
                      add r9,4
                      cmp r8d,r10d
                      jl _loop2

                      Literally the same thing, it even used the same registers.

                      P 1 Reply Last reply
                      0
                      • L Lost User

                        What's wrong with foreach?

                        F Offline
                        F Offline
                        F ES Sitecore
                        wrote on last edited by
                        #11

                        harold aptroot wrote:

                        What's wrong with foreach?

                        The young'uns prefer using linq for everything these days. Apparently unreadable, single-line, non-debugabble code using slow features like anonymous methods is the way to go :)

                        1 Reply Last reply
                        0
                        • L Lost User

                          OK, but that may be a bit outdated - for example, the difference between private static int test1(int[] ar) { int sum = 0; foreach (var i in ar) { sum += i; } return sum; } and private static int test2(int[] ar) { int sum = 0; for (int i = 0; i < ar.Length; i++) { sum += ar[i]; } return sum; } Is .. not much. The loop bodies are

                          _loop1:
                          mov eax,dword ptr [rdx+r9+10h]
                          add ecx,eax
                          inc r8d
                          add r9,4
                          cmp r8d,r10d
                          jl _loop1

                          _loop2:
                          mov eax,dword ptr [rdx+r9+10h]
                          add ecx,eax
                          inc r8d
                          add r9,4
                          cmp r8d,r10d
                          jl _loop2

                          Literally the same thing, it even used the same registers.

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

                          Now try the for in reverse. And try it with something more complex than an array of ints.

                          L 1 Reply Last reply
                          0
                          • P PIEBALDconsult

                            Now try the for in reverse. And try it with something more complex than an array of ints.

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

                            Well you can't foreach in reverse so.. Obviously for is more general.

                            P 1 Reply Last reply
                            0
                            • L Lost User

                              Well you can't foreach in reverse so.. Obviously for is more general.

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

                              foreach is more general in that it can work on any IEnumerable, whereas for is more general in that it doesn't require an IEnumerable. ::shrug:: I find that for, particularly a reverse for (which reduces calls to Length or Count or whatever), can perform much better than foreach. Though the actual time saved may not be significant, still you don't know what else is going on in the system. On why to use DataViews[^]

                              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