string or String?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Bogdan

    string or String?

    As a mainly C/C++ and Java developer I was quite surprised when I realized
    that C# compiler takes both "string" and "String" types. C# is case
    sensitive so I'm a bit puzzled by that. Could someone please explain that
    or point me to on-line docs?

    thx


  • sloan

    #2
    Re: string or String?

    The string type represents a sequence of zero or more Unicode characters.
    string is an alias for String in the .NET Framework.






    "Bogdan" <bogdan@domain. comwrote in message
    news:eAk$Hv5gIH A.3352@TK2MSFTN GP04.phx.gbl...
    As a mainly C/C++ and Java developer I was quite surprised when I realized
    that C# compiler takes both "string" and "String" types. C# is case
    sensitive so I'm a bit puzzled by that. Could someone please explain
    that or point me to on-line docs?
    >
    thx
    >

    Comment

    • Martin Bonner

      #3
      Re: string or String?

      On Mar 11, 5:17 pm, "Bogdan" <bog...@domain. comwrote:
      As a mainly C/C++ and Java developer I was quite surprised when I realized
      that C# compiler takes both "string" and "String" types. C# is case
      sensitive so I'm a bit puzzled by that. Could someone please explain that
      or point me to on-line docs?
      Actually C# doesn't understand a String type. It does understand a
      System.String type, and you can refer to that as just String, if you
      happen to have a
      using System;
      statement at the top of your file (and it is some time since I saw a
      C# file that /didn't/ have such a statement).

      C# does understand the 'string' type, which it internally converts to
      System.String32 (much as it converts 'short' to System.Int16).

      My personal preference is to always use the C# names, unless I want to
      emphasize the exact length of an integer (in which case, I'll use
      System.Int64 or whatever).

      Comment

      • =?ISO-8859-1?Q?Arne_Vajh=F8j?=

        #4
        Re: string or String?

        Martin Bonner wrote:
        Actually C# doesn't understand a String type. It does understand a
        System.String type, and you can refer to that as just String, if you
        happen to have a
        using System;
        statement at the top of your file (and it is some time since I saw a
        C# file that /didn't/ have such a statement).
        I think most C# programmers will expect it to be there.
        C# does understand the 'string' type, which it internally converts to
        System.String32 (much as it converts 'short' to System.Int16).
        s/32//w
        My personal preference is to always use the C# names, unless I want to
        emphasize the exact length of an integer (in which case, I'll use
        System.Int64 or whatever).
        Me too.

        But I suspect that it is because I also code in C/C++/Java.

        Arne

        Comment

        • Martin Bonner

          #5
          Re: string or String?

          On Mar 12, 1:35 am, Arne Vajhøj <a...@vajhoej.d kwrote:
          Martin Bonner wrote:
          Actually C# doesn't understand a String type. It does understand a
          System.String type, and you can refer to that as just String, if you
          happen to have a
          using System;
          statement at the top of your file (and it is some time since I saw a
          C# file that /didn't/ have such a statement).
          >
          I think most C# programmers will expect it to be there.
          >
          C# does understand the 'string' type, which it internally converts to
          System.String32 (much as it converts 'short' to System.Int16).
          >
          s/32//w
          D'oh! :-)
          >
          My personal preference is to always use the C# names, unless I want to
          emphasize the exact length of an integer (in which case, I'll use
          System.Int64 or whatever).
          >
          Me too.
          >
          But I suspect that it is because I also code in C/C++/Java.
          Perhaps, but I think I would recommend it as a good convention even
          for a pure C# development.

          Comment

          • Marc Gravell

            #6
            Re: string or String?

            My personal preference is to always use the C# names, unless I want to
            emphasize the exact length of an integer (in which case, I'll use
            System.Int64 or whatever).
            This is also good practice if you are exposing the name as part of a method
            (or other API etc), since the caller could be any language. Examples:
            IDataReader.Get Int32(), Convert.ToInt64 ()

            Marc


            Comment

            Working...