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. General Programming
  3. C#
  4. string vs String functions

string vs String functions

Scheduled Pinned Locked Moved C#
questioncsharpvisual-studio
6 Posts 6 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.
  • S Offline
    S Offline
    senylity
    wrote on last edited by
    #1

    I have been developing for a while now, mostly in VB. But now I have seen the light and joined the C# parade. Anywho, is there a difference between the functions and use of string. functions and String. functions? I use .Empty, .IsNullOrEmpty, and .Format all the time. Does it really matter if I use string. or String.? I know that one is a type, but besides the color in VS, what is the difference, and should I use one or the other?

    Success is the happy feeling you get between the time you do something and the time you tell a woman what you did. --Dibert

    D S K 3 Replies Last reply
    0
    • S senylity

      I have been developing for a while now, mostly in VB. But now I have seen the light and joined the C# parade. Anywho, is there a difference between the functions and use of string. functions and String. functions? I use .Empty, .IsNullOrEmpty, and .Format all the time. Does it really matter if I use string. or String.? I know that one is a type, but besides the color in VS, what is the difference, and should I use one or the other?

      Success is the happy feeling you get between the time you do something and the time you tell a woman what you did. --Dibert

      D Offline
      D Offline
      Daniel Grunwald
      wrote on last edited by
      #2

      string is a C# keyword that is an alias to System.String. If you have "using System;" in your file and you don't have any other class named String, then String (the class) and string (the C# keyword) are equivalent. Otherwise String may refer to your own String class, while string always refers to the built-in string class. Another difference: you may use String as a name for local variables (if you like to confuse people reading your code), but string is reserved. But normally using string or String makes no difference, both compile to the same IL.

      A L 2 Replies Last reply
      0
      • D Daniel Grunwald

        string is a C# keyword that is an alias to System.String. If you have "using System;" in your file and you don't have any other class named String, then String (the class) and string (the C# keyword) are equivalent. Otherwise String may refer to your own String class, while string always refers to the built-in string class. Another difference: you may use String as a name for local variables (if you like to confuse people reading your code), but string is reserved. But normally using string or String makes no difference, both compile to the same IL.

        A Offline
        A Offline
        Aaron VanWieren
        wrote on last edited by
        #3

        I've always been told to always use the lower case as it makes it easier to read on others who are viewing your code (unless they come from jave)! Also, you should learn all about string builders. They are the best item for creating multi component strings and they only are created once, not every time you add another string element. Sorry for the diatribe.

        _____________________________________________________________________ Our developers never release code. Rather, it tends to escape, pillaging the countryside all around. The Enlightenment Project (paraphrased comment) Visit Me at GISDevCafe

        1 Reply Last reply
        0
        • D Daniel Grunwald

          string is a C# keyword that is an alias to System.String. If you have "using System;" in your file and you don't have any other class named String, then String (the class) and string (the C# keyword) are equivalent. Otherwise String may refer to your own String class, while string always refers to the built-in string class. Another difference: you may use String as a name for local variables (if you like to confuse people reading your code), but string is reserved. But normally using string or String makes no difference, both compile to the same IL.

          L Offline
          L Offline
          Luc Pattyn
          wrote on last edited by
          #4

          I would not recommend writing your own String class; too confusing ! :)

          Luc Pattyn [My Articles]

          1 Reply Last reply
          0
          • S senylity

            I have been developing for a while now, mostly in VB. But now I have seen the light and joined the C# parade. Anywho, is there a difference between the functions and use of string. functions and String. functions? I use .Empty, .IsNullOrEmpty, and .Format all the time. Does it really matter if I use string. or String.? I know that one is a type, but besides the color in VS, what is the difference, and should I use one or the other?

            Success is the happy feeling you get between the time you do something and the time you tell a woman what you did. --Dibert

            S Offline
            S Offline
            Scott Dorman
            wrote on last edited by
            #5

            There really isn't any difference. string is the C# alias for System.String, which is the actual CLR data type. I personally use string when declaring variables and String when calling functions (like .Empty, .IsNullOrEmpty, and .Format) as I think it makes it a little clearer; but that is simply personal preference and string.Format is exactly the same as String.Format.

            ----------------------------- In just two days, tomorrow will be yesterday.

            1 Reply Last reply
            0
            • S senylity

              I have been developing for a while now, mostly in VB. But now I have seen the light and joined the C# parade. Anywho, is there a difference between the functions and use of string. functions and String. functions? I use .Empty, .IsNullOrEmpty, and .Format all the time. Does it really matter if I use string. or String.? I know that one is a type, but besides the color in VS, what is the difference, and should I use one or the other?

              Success is the happy feeling you get between the time you do something and the time you tell a woman what you did. --Dibert

              K Offline
              K Offline
              Keshav V Kamat 0
              wrote on last edited by
              #6

              String may refer to your own class, string refers to the inbuilt string class

              Keshav Kamat :) India

              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