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. Other Discussions
  3. The Soapbox
  4. Useful, but Overlooked C# Features

Useful, but Overlooked C# Features

Scheduled Pinned Locked Moved The Soapbox
csharpasp-netdotnetcomhelp
15 Posts 9 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.
  • R realJSOP

    What does this topic have to do with American politics? To stay on-topic in the Soapbox, you have to mention on of the following: 0) abortion 1) global warming 2) LGBTQHIJKLMNOP 3) Illegal immigration 4) Trump 5) Advocate the use of Visual Basic for anything related to programming

    ".45 ACP - because shooting twice is just silly" - JSOP, 2010
    -----
    You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
    -----
    When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013

    S Offline
    S Offline
    Slacker007
    wrote on last edited by
    #5
    1. must identify as something other than human OR really dislike people who identify as something other than human.
    D 1 Reply Last reply
    0
    • R realJSOP

      What does this topic have to do with American politics? To stay on-topic in the Soapbox, you have to mention on of the following: 0) abortion 1) global warming 2) LGBTQHIJKLMNOP 3) Illegal immigration 4) Trump 5) Advocate the use of Visual Basic for anything related to programming

      ".45 ACP - because shooting twice is just silly" - JSOP, 2010
      -----
      You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
      -----
      When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013

      J Offline
      J Offline
      Jorgen Andersson
      wrote on last edited by
      #6
      1. The second amendment.

      Wrong is evil and must be defeated. - Jeff Ello

      R 1 Reply Last reply
      0
      • R realJSOP

        What does this topic have to do with American politics? To stay on-topic in the Soapbox, you have to mention on of the following: 0) abortion 1) global warming 2) LGBTQHIJKLMNOP 3) Illegal immigration 4) Trump 5) Advocate the use of Visual Basic for anything related to programming

        ".45 ACP - because shooting twice is just silly" - JSOP, 2010
        -----
        You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
        -----
        When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #7
        1. food ?

        Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^] "If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.

        1 Reply Last reply
        0
        • J Jorgen Andersson
          1. The second amendment.

          Wrong is evil and must be defeated. - Jeff Ello

          R Offline
          R Offline
          realJSOP
          wrote on last edited by
          #8

          The 2nd Amendment guarantees that you'll be able to defend your right to use 0-indexed lists.

          ".45 ACP - because shooting twice is just silly" - JSOP, 2010
          -----
          You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
          -----
          When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013

          D 1 Reply Last reply
          0
          • D David A Gray

            most anything that Scott Hanselman writes, [Clever little C# and ASP.NET Core features that make me happy - Scott Hanselman](https://www.hanselman.com/blog/CleverLittleCAndASPNETCoreFeaturesThatMakeMeHappy.aspx) is worthwhile reading. This article reminded me about type aliases, a feature that I discovered about 3 years ago, but frequently forget to use when it would improve the code. The other feature covered, out var parameters, isn't something that I considered to be a separate feature. Out parameters have been around since the beginning, and var has been part of the language for quite a while, too. Hence, it never occurred to me to consider the combination of the two as a new feature. While I dislike var on the whole because it smells of loose variable typing, I have discovered that it has a place, especially in new code that is a work in progress. As recently as yesterday, I defined a var because I wasn't certain of the return type from the method that I was exploring. Before I mark the project as completed, the var will almost certainly morph into something a lot more explicit.

            David A. Gray Delivering Solutions for the Ages, One Problem at a Time Interpreting the Fundamental Principle of Tabular Reporting

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

            David A. Gray wrote:

            Before I mark the project as completed, the var will almost certainly morph into something a lot more explicit.

            Hover your mouse over it, and it will tell you how it is resolved. Use that and be specific.

            Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^] "If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.

            D 1 Reply Last reply
            0
            • S Slacker007
              1. must identify as something other than human OR really dislike people who identify as something other than human.
              D Offline
              D Offline
              Daniel Pfeffer
              wrote on last edited by
              #10

              I'd love to have a conversation with an intelligent member of another species. Come to think of it, I wouldn't mind a conversation with an intelligent member of my species - if I could find one... :-\

              Freedom is the freedom to say that two plus two make four. If that is granted, all else follows. -- 6079 Smith W.

              1 Reply Last reply
              0
              • R realJSOP

                The 2nd Amendment guarantees that you'll be able to defend your right to use 0-indexed lists.

                ".45 ACP - because shooting twice is just silly" - JSOP, 2010
                -----
                You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
                -----
                When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013

                D Offline
                D Offline
                Daniel Pfeffer
                wrote on last edited by
                #11

                :thumbsup:

                Freedom is the freedom to say that two plus two make four. If that is granted, all else follows. -- 6079 Smith W.

                1 Reply Last reply
                0
                • D David A Gray

                  most anything that Scott Hanselman writes, [Clever little C# and ASP.NET Core features that make me happy - Scott Hanselman](https://www.hanselman.com/blog/CleverLittleCAndASPNETCoreFeaturesThatMakeMeHappy.aspx) is worthwhile reading. This article reminded me about type aliases, a feature that I discovered about 3 years ago, but frequently forget to use when it would improve the code. The other feature covered, out var parameters, isn't something that I considered to be a separate feature. Out parameters have been around since the beginning, and var has been part of the language for quite a while, too. Hence, it never occurred to me to consider the combination of the two as a new feature. While I dislike var on the whole because it smells of loose variable typing, I have discovered that it has a place, especially in new code that is a work in progress. As recently as yesterday, I defined a var because I wasn't certain of the return type from the method that I was exploring. Before I mark the project as completed, the var will almost certainly morph into something a lot more explicit.

                  David A. Gray Delivering Solutions for the Ages, One Problem at a Time Interpreting the Fundamental Principle of Tabular Reporting

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

                  I wouldn't consider var as being part of the language, the compiler simply replaces it with the proper type. If you look at decompiled .net code you'll never see a "var". Or a case statement.

                  D 1 Reply Last reply
                  0
                  • P Pualee

                    I had a strong dislike for C# var at first. I had a c++ background, and then worked in VB6. VAR was evil and had terrible side effects. However, in C#, even though it is 'var', it is strongly typed. So all the evil of VB6 is gone really. It does help the code look neater too. I have been assimilated.

                    D Offline
                    D Offline
                    den2k88
                    wrote on last edited by
                    #13

                    You too survived Variants, I see. I served from 2012 to 2018... bad times.

                    GCS d--(d+) s-/++ a C++++ U+++ P- L+@ E-- W++ N+ o+ K- w+++ O? M-- V? PS+ PE- Y+ PGP t+ 5? X R+++ tv-- b+(+++) DI+++ D++ G e++ h--- r+++ y+++*      Weapons extension: ma- k++ F+2 X

                    1 Reply Last reply
                    0
                    • L Lost User

                      David A. Gray wrote:

                      Before I mark the project as completed, the var will almost certainly morph into something a lot more explicit.

                      Hover your mouse over it, and it will tell you how it is resolved. Use that and be specific.

                      Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^] "If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.

                      D Offline
                      D Offline
                      David A Gray
                      wrote on last edited by
                      #14

                      Quote:

                      Hover your mouse over it, and it will tell you how it is resolved.

                      Absolutely! That's what I meant about it morphing into something more specific. Though the var type isn't technically "loosely typed," its type is formally undocumented. To my way of thinking, that is enough to qualify it as a code smell.

                      David A. Gray Delivering Solutions for the Ages, One Problem at a Time Interpreting the Fundamental Principle of Tabular Reporting

                      1 Reply Last reply
                      0
                      • F F ES Sitecore

                        I wouldn't consider var as being part of the language, the compiler simply replaces it with the proper type. If you look at decompiled .net code you'll never see a "var". Or a case statement.

                        D Offline
                        D Offline
                        David A Gray
                        wrote on last edited by
                        #15

                        Quote:

                        I wouldn't consider var as being part of the language, the compiler simply replaces it with the proper type. If you look at decompiled .net code you'll never see a "var

                        Nor will you see a var type in the locals and watch windows of the debugger.

                        Quote:

                        Or a case statement.

                        The same holds true for C and C++. Moreover, in all three programming languages, for is actually three statements, each implemented as one or two machine instructions.

                        David A. Gray Delivering Solutions for the Ages, One Problem at a Time Interpreting the Fundamental Principle of Tabular Reporting

                        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