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. String or string?

String or string?

Scheduled Pinned Locked Moved The Lounge
csharpdotnetquestion
62 Posts 17 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 Lost User

    We already got that sorted out, I think. Int32 is not a class, it's a struct. Now it makes sense and you are right. It makes no difference.

    The language is JavaScript. that of Mordor, which I will not utter here
    This is Javascript. If you put big wheels and a racing stripe on a golf cart, it's still a fucking golf cart.
    "I don't know, extraterrestrial?" "You mean like from space?" "No, from Canada." If software development were a circus, we would all be the clowns.

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

    structs are also classes... (PIEBALD exits quickly...)

    L 1 Reply Last reply
    0
    • P PIEBALDconsult

      No, there is no difference.

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

      Ok, then it's time to do some reading.

      The language is JavaScript. that of Mordor, which I will not utter here
      This is Javascript. If you put big wheels and a racing stripe on a golf cart, it's still a fucking golf cart.
      "I don't know, extraterrestrial?" "You mean like from space?" "No, from Canada." If software development were a circus, we would all be the clowns.

      1 Reply Last reply
      0
      • R Richard Deeming

        PIEBALDconsult wrote:

        What I find crazy is that when specifying the underlying type for an enumeration, you must use the alias. X|

        Not if you're using the Roslyn (C# 6 / VS2015) compiler:

        enum Foo : Int32
        {
        Bar,
        Baz,
        }


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

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

        No thanks. I prefer to write backward-compatible code unless there's a real reason to do otherwise.

        1 Reply Last reply
        0
        • P PIEBALDconsult

          structs are also classes... (PIEBALD exits quickly...)

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

          I know, but they are not treated as reference types and ... I have a better idea. here its past 11 PM now. Do you have something to drink?

          The language is JavaScript. that of Mordor, which I will not utter here
          This is Javascript. If you put big wheels and a racing stripe on a golf cart, it's still a fucking golf cart.
          "I don't know, extraterrestrial?" "You mean like from space?" "No, from Canada." If software development were a circus, we would all be the clowns.

          1 Reply Last reply
          0
          • B Bryian Tan

            Even though we use the String, Int32, etc... correctly per Microsoft website, in VS, Intellisense will display suggestion "name can be simplified", "Show potential fixes", IDE0001 C# Name can be simplified. Isn't that "Show potential fixes" = there is a bug and here is the potential fix? Why Microsoft didn't fix it to clear this confusion? After all VS is Microsoft product right? Maybe there is a reason behind it, and we all going to like it ;P ;P ;P

            Bryian Tan

            J Offline
            J Offline
            Jon McKee
            wrote on last edited by
            #40

            I believe the reason it suggests to simplify the name is because string, int, etc do not require the System namespace include while String, Int32, etc still do. It can help clean up your namespace includes if that file doesn't use the System namespace for things other than simple types :thumbsup: I'm sure there are other reasons to suggest simplification but that's the one that immediately comes to mind. EDIT: Now that I think about it, in a way the simple names "decouple" the developer from the exact underlying type too. They could transparently change int to map to Int64 in the future, for example.

            G P 2 Replies Last reply
            0
            • F Forogar

              When writing my C# code I was in the habit of using string (all lowercase) for strings declarations, etc. and String (capitalized) for method calls such as String.Empty and String.Format just as a sort of aide memoir that I was calling an object method. As I started to create String extension methods I reviewed this habit of mine and decided this was a pointless differentiation and switched to just using string all the time. At the same time I decided that my using Int32 for methods such as Int32.TryParse and just int in declarations, etc. was also pointless and perhaps confusing to others and so switched to using int all the time instead. It all compiles to the same IL code anyway so it was just a matter of style really. What do you think?

              - I would love to change the world, but they won’t give me the source code.

              N Offline
              N Offline
              NickPace
              wrote on last edited by
              #41

              Switch to Java. Problem solved

              -NP Never underestimate the creativity of the end-user

              F H 2 Replies Last reply
              0
              • L Lost User

                We already got that sorted out, I think. Int32 is not a class, it's a struct. Now it makes sense and you are right. It makes no difference.

                The language is JavaScript. that of Mordor, which I will not utter here
                This is Javascript. If you put big wheels and a racing stripe on a golf cart, it's still a fucking golf cart.
                "I don't know, extraterrestrial?" "You mean like from space?" "No, from Canada." If software development were a circus, we would all be the clowns.

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

                Do you feel how wrong you are? X|

                1 Reply Last reply
                0
                • F Forogar

                  When writing my C# code I was in the habit of using string (all lowercase) for strings declarations, etc. and String (capitalized) for method calls such as String.Empty and String.Format just as a sort of aide memoir that I was calling an object method. As I started to create String extension methods I reviewed this habit of mine and decided this was a pointless differentiation and switched to just using string all the time. At the same time I decided that my using Int32 for methods such as Int32.TryParse and just int in declarations, etc. was also pointless and perhaps confusing to others and so switched to using int all the time instead. It all compiles to the same IL code anyway so it was just a matter of style really. What do you think?

                  - I would love to change the world, but they won’t give me the source code.

                  G Offline
                  G Offline
                  Gary R Wheeler
                  wrote on last edited by
                  #43

                  I write process control applications, so I have to deal with lots of values that are defined as a particular number of bits in a network interface or a hardware register. For that reason I use Int32, UInt16, and so on. While I realize the chances of the aliases changing underlying type in .NET are effectively zero, I have too many battle scars from prior apps written in C. A variable declared as an int could be 16 bits, 32 bits, 64 bits, or something else. That said, string's are another story entirely. Character sets, code pages, encoding, decoding, you still end up doing conversions of one sort or another regardless of your 'native' representation. I don't think I've ever declared a String in almost 10 years of C#. I always use the string alias.

                  Software Zen: delete this;

                  1 Reply Last reply
                  0
                  • J Jon McKee

                    I believe the reason it suggests to simplify the name is because string, int, etc do not require the System namespace include while String, Int32, etc still do. It can help clean up your namespace includes if that file doesn't use the System namespace for things other than simple types :thumbsup: I'm sure there are other reasons to suggest simplification but that's the one that immediately comes to mind. EDIT: Now that I think about it, in a way the simple names "decouple" the developer from the exact underlying type too. They could transparently change int to map to Int64 in the future, for example.

                    G Offline
                    G Offline
                    Gary R Wheeler
                    wrote on last edited by
                    #44

                    Jon McKee wrote:

                    They could transparently change int to map to Int64 in the future, for example

                    They could, but won't. There are way too many things that would go crash-bang-BOOM if they did.

                    Software Zen: delete this;

                    J 1 Reply Last reply
                    0
                    • Sander RosselS Sander Rossel

                      I used to do the same, string variable and String.Format(...) and int variable and Int32.Parse(...). There was a good reason I did that though, Microsoft recommended doing it! Until I switched to Visual Studio 2015 and all of a sudden it started giving me "tips" to simplify String to string and Int32 to int... Thanks Microsoft, for sticking to your own guidelines :~ For the same reason I stopped using this and base (unless necessary) and TheClassImIn.StaticMethod instead of simply StaticMethod. And yes, I know I can turn off those rules, but I like sticking to defaults :)

                      Best, Sander arrgh.js - Bringing LINQ to JavaScript SQL Server for C# Developers Succinctly Object-Oriented Programming in C# Succinctly

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

                      Great, if you think String and string and int and Int32 are comparable ....

                      Sander RosselS 1 Reply Last reply
                      0
                      • G Gary R Wheeler

                        Jon McKee wrote:

                        They could transparently change int to map to Int64 in the future, for example

                        They could, but won't. There are way too many things that would go crash-bang-BOOM if they did.

                        Software Zen: delete this;

                        J Offline
                        J Offline
                        Jon McKee
                        wrote on last edited by
                        #46

                        True. More of a thought on possibility rather than implementation :)

                        1 Reply Last reply
                        0
                        • J Jon McKee

                          I believe the reason it suggests to simplify the name is because string, int, etc do not require the System namespace include while String, Int32, etc still do. It can help clean up your namespace includes if that file doesn't use the System namespace for things other than simple types :thumbsup: I'm sure there are other reasons to suggest simplification but that's the one that immediately comes to mind. EDIT: Now that I think about it, in a way the simple names "decouple" the developer from the exact underlying type too. They could transparently change int to map to Int64 in the future, for example.

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

                          Well, if someone ports .net to an 8-bit OS...

                          1 Reply Last reply
                          0
                          • F Forogar

                            When writing my C# code I was in the habit of using string (all lowercase) for strings declarations, etc. and String (capitalized) for method calls such as String.Empty and String.Format just as a sort of aide memoir that I was calling an object method. As I started to create String extension methods I reviewed this habit of mine and decided this was a pointless differentiation and switched to just using string all the time. At the same time I decided that my using Int32 for methods such as Int32.TryParse and just int in declarations, etc. was also pointless and perhaps confusing to others and so switched to using int all the time instead. It all compiles to the same IL code anyway so it was just a matter of style really. What do you think?

                            - I would love to change the world, but they won’t give me the source code.

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

                            I think I will be explicit if the (Win) API is requiring an Int32, and non-specific in the code where I need an int. One can change, the other will not.

                            Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^][](X-Clacks-Overhead: GNU Terry Pratchett)

                            1 Reply Last reply
                            0
                            • L Lost User

                              Great, if you think String and string and int and Int32 are comparable ....

                              Sander RosselS Offline
                              Sander RosselS Offline
                              Sander Rossel
                              wrote on last edited by
                              #49

                              They are, just read the documentation! Both implement IComparable and IComparable<T>. They implement some other interfaces too, like IEquatable and IConvertible.

                              Best, Sander arrgh.js - Bringing LINQ to JavaScript SQL Server for C# Developers Succinctly Object-Oriented Programming in C# Succinctly

                              L 1 Reply Last reply
                              0
                              • F Forogar

                                When writing my C# code I was in the habit of using string (all lowercase) for strings declarations, etc. and String (capitalized) for method calls such as String.Empty and String.Format just as a sort of aide memoir that I was calling an object method. As I started to create String extension methods I reviewed this habit of mine and decided this was a pointless differentiation and switched to just using string all the time. At the same time I decided that my using Int32 for methods such as Int32.TryParse and just int in declarations, etc. was also pointless and perhaps confusing to others and so switched to using int all the time instead. It all compiles to the same IL code anyway so it was just a matter of style really. What do you think?

                                - I would love to change the world, but they won’t give me the source code.

                                M Offline
                                M Offline
                                Mark_Wallace
                                wrote on last edited by
                                #50

                                Given all the confusion, I think I'll just override String and string, in future, with an array (which is all a string is meant to be, anyway).

                                I wanna be a eunuchs developer! Pass me a bread knife!

                                1 Reply Last reply
                                0
                                • P PIEBALDconsult

                                  Cornelius Henning wrote:

                                  I believe at some point in the past this was the case??

                                  Nope, never. It's just an alias.

                                  string
                                  Visual Studio .NET 2003
                                  The string type represents a string of Unicode characters. string is an alias for System.String in the .NET Framework.

                                  S Offline
                                  S Offline
                                  Slacker007
                                  wrote on last edited by
                                  #51

                                  :thumbsup:

                                  1 Reply Last reply
                                  0
                                  • F Forogar

                                    When writing my C# code I was in the habit of using string (all lowercase) for strings declarations, etc. and String (capitalized) for method calls such as String.Empty and String.Format just as a sort of aide memoir that I was calling an object method. As I started to create String extension methods I reviewed this habit of mine and decided this was a pointless differentiation and switched to just using string all the time. At the same time I decided that my using Int32 for methods such as Int32.TryParse and just int in declarations, etc. was also pointless and perhaps confusing to others and so switched to using int all the time instead. It all compiles to the same IL code anyway so it was just a matter of style really. What do you think?

                                    - I would love to change the world, but they won’t give me the source code.

                                    M Offline
                                    M Offline
                                    Marc Clifton
                                    wrote on last edited by
                                    #52

                                    What I find amusing is that VS2015 says that String.Empty can be simplified to string.Empty Riiight. Marc

                                    V.A.P.O.R.ware - Visual Assisted Programming / Organizational Representation Learning to code with python is like learning to swim with those little arm floaties. It gives you undeserved confidence and will eventually drown you. - DangerBunny Artificial intelligence is the only remedy for natural stupidity. - CDP1802

                                    L 1 Reply Last reply
                                    0
                                    • Sander RosselS Sander Rossel

                                      They are, just read the documentation! Both implement IComparable and IComparable<T>. They implement some other interfaces too, like IEquatable and IConvertible.

                                      Best, Sander arrgh.js - Bringing LINQ to JavaScript SQL Server for C# Developers Succinctly Object-Oriented Programming in C# Succinctly

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

                                      I did not mean this Kind of comparable (IComparable etc) :-D I meant compare the two Scenarios :laugh:

                                      Sander RosselS 1 Reply Last reply
                                      0
                                      • M Marc Clifton

                                        What I find amusing is that VS2015 says that String.Empty can be simplified to string.Empty Riiight. Marc

                                        V.A.P.O.R.ware - Visual Assisted Programming / Organizational Representation Learning to code with python is like learning to swim with those little arm floaties. It gives you undeserved confidence and will eventually drown you. - DangerBunny Artificial intelligence is the only remedy for natural stupidity. - CDP1802

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

                                        Indeed a kind amusing. But if you claim this to MS the Chance is there that a over all "empty I can be everything" will be defined ... and after they will make c# a Java language. No, please not :laugh:

                                        1 Reply Last reply
                                        0
                                        • L Lost User

                                          I did not mean this Kind of comparable (IComparable etc) :-D I meant compare the two Scenarios :laugh:

                                          Sander RosselS Offline
                                          Sander RosselS Offline
                                          Sander Rossel
                                          wrote on last edited by
                                          #55

                                          I know what you meant, I just to chose to interpret it differently ;p

                                          Best, Sander arrgh.js - Bringing LINQ to JavaScript SQL Server for C# Developers Succinctly Object-Oriented Programming in C# Succinctly

                                          L 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