String or string

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?R3JlZw==?=

    String or string

    I've noticed two different "String" variable declarations to choose from. One
    uses an upper case "S" and the other uses a lower case "s". The upper case
    appears in a light green color, while the lower case appears as blue. If I go
    to the the variable's definition the same definition appears for each, which
    suggests to me these must be the same type.

    Is there actually a different meaning for each type and what would this
    difference be? And, if different, is one better to use than the other, with
    performance in mind?

    Can anyone shed some light on this for me?

    Thanks.
  • Alberto Poblacion

    #2
    Re: String or string

    "Greg" <AccessVBAnet@n ewsgroups.nospa mwrote in message
    news:EDC70C28-0117-40CB-9B11-1B75E88208BA@mi crosoft.com...
    I've noticed two different "String" variable declarations to choose from.
    One
    uses an upper case "S" and the other uses a lower case "s". The upper case
    appears in a light green color, while the lower case appears as blue. If I
    go
    to the the variable's definition the same definition appears for each,
    which
    suggests to me these must be the same type.
    >
    Is there actually a different meaning for each type and what would this
    difference be? And, if different, is one better to use than the other,
    with
    performance in mind?
    "string" is a compiler synonym for System.String (in the same way as "int"
    is a synonym for System.Int32), and appears blue because it is a reserved
    word.
    "String", since you are already "using System;", becomes System.String (and
    appears light green because it is a class name).

    So in both cases you end up with a System.String. There shouldn't be any
    difference in the compiled code.

    Comment

    • William Stacey

      #3
      Re: String or string

      System.String is the actual type. "string" is effectively an alias for
      System.String.

      System.String s = "";
      string s2 = ""

      The compiler alias "string" just maps to System.String. Same with the other
      types.

      "Greg" <AccessVBAnet@n ewsgroups.nospa mwrote in message
      news:EDC70C28-0117-40CB-9B11-1B75E88208BA@mi crosoft.com...
      I've noticed two different "String" variable declarations to choose from.
      One
      uses an upper case "S" and the other uses a lower case "s". The upper case
      appears in a light green color, while the lower case appears as blue. If I
      go
      to the the variable's definition the same definition appears for each,
      which
      suggests to me these must be the same type.
      >
      Is there actually a different meaning for each type and what would this
      difference be? And, if different, is one better to use than the other,
      with
      performance in mind?
      >
      Can anyone shed some light on this for me?
      >
      Thanks.

      Comment

      • MC

        #4
        Re: String or string


        "Greg" <AccessVBAnet@n ewsgroups.nospa mwrote in message
        news:EDC70C28-0117-40CB-9B11-1B75E88208BA@mi crosoft.com...
        I've noticed two different "String" variable declarations to choose from.
        One
        uses an upper case "S" and the other uses a lower case "s". The upper case
        appears in a light green color, while the lower case appears as blue. If I
        go
        to the the variable's definition the same definition appears for each,
        which
        suggests to me these must be the same type.
        >
        Is there actually a different meaning for each type and what would this
        difference be? And, if different, is one better to use than the other,
        with
        performance in mind?
        String and string mean the same thing but are in two different series of
        names.

        There is a C# series of names (string, int, etc.) and a .NET
        language-independent series (String, Int32, etc.). Many types exist only in
        the second series of names. When a type has names in both series, you can
        use either one.


        Comment

        • Granville Barnett

          #5
          Re: String or string


          "MC" <for.address.lo ok@www.ai.uga.e du.slash.mcwrot e in message
          news:esYMTOjLJH A.4452@TK2MSFTN GP05.phx.gbl...
          >
          "Greg" <AccessVBAnet@n ewsgroups.nospa mwrote in message
          news:EDC70C28-0117-40CB-9B11-1B75E88208BA@mi crosoft.com...
          >I've noticed two different "String" variable declarations to choose from.
          >One
          >uses an upper case "S" and the other uses a lower case "s". The upper
          >case
          >appears in a light green color, while the lower case appears as blue. If
          >I go
          >to the the variable's definition the same definition appears for each,
          >which
          >suggests to me these must be the same type.
          >>
          >Is there actually a different meaning for each type and what would this
          >difference be? And, if different, is one better to use than the other,
          >with
          >performance in mind?
          >
          String and string mean the same thing but are in two different series of
          names.
          >
          There is a C# series of names (string, int, etc.) and a .NET
          language-independent series (String, Int32, etc.). Many types exist only
          in the second series of names. When a type has names in both series, you
          can use either one.
          >
          Greg, I would use string as it is the *norm* in most source code. The same
          can be said for int but it has a few caveats, e.g. if you are working in a
          code base where you delve in and out of using 32 and 64 bit ints then it may
          make sense to be explicit, i.e. Int32 (not int), Int64 - this seems to
          provide a nice differentiation between the two.

          Granville

          Comment

          • =?UTF-8?B?R8O2cmFuIEFuZGVyc3Nvbg==?=

            #6
            Re: String or string

            As already have been said in the thread, they result in the same type.

            It's only in a few situations that the CRL type and the C# alias are not
            fully interchangeable . For example as a base type for enums:

            enum test1 : int { A, B, C }; // int is valid
            enum test2 : Int32 { A, B, C }; // Int32 is not valid

            --
            Göran Andersson
            _____
            Göran Anderssons privata hemsida.

            Comment

            • =?UTF-8?B?QXJuZSBWYWpow7hq?=

              #7
              Re: String or string

              Greg wrote:
              I've noticed two different "String" variable declarations to choose from. One
              uses an upper case "S" and the other uses a lower case "s". The upper case
              appears in a light green color, while the lower case appears as blue. If I go
              to the the variable's definition the same definition appears for each, which
              suggests to me these must be the same type.
              >
              Is there actually a different meaning for each type and what would this
              difference be? And, if different, is one better to use than the other, with
              performance in mind?
              No difference just a matter of style.

              I believe string (C# language style) is favored over
              String (.NET framework style) by the majority.

              Arne

              Comment

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

                #8
                Re: String or string

                Granville Barnett wrote:
                Greg, I would use string as it is the *norm* in most source code. The
                same can be said for int but it has a few caveats, e.g. if you are
                working in a code base where you delve in and out of using 32 and 64 bit
                ints then it may make sense to be explicit, i.e. Int32 (not int), Int64
                - this seems to provide a nice differentiation between the two.
                Depends on whether you consider knowing that int is 32 bit in C#
                is a basic requirement for all C# developers.

                I tend to think so.

                Arne

                Comment

                Working...