50

Possible Duplicate:
In C# what is the difference between String and string

Should I use string or String when declaring a basic string variable in c# and does it matter?

Community
  • 1
  • 1
mcass20
  • 1,668
  • 1
  • 22
  • 39

4 Answers4

32

I like string because VS highlights it in dark blue (which makes it awesomer).

Greg
  • 16,540
  • 9
  • 51
  • 97
20

It doesn't matter, though it's best to be consistent: lower-case string is an alias for String.

Jeff Sternal
  • 47,787
  • 8
  • 93
  • 120
7

The string keyword is an alias for System.String.

(The same goes for int - System.Int32 long - System.Int64 and so on)

C# doesn't have two different representations for primitives the same way that Java does. (Where an int is far different from an Integer)

In most cases it is best to use lowercase string because it is an alias to the fully qualified System.String. This way you can avoid type conflicts if there is another String type somewhere in your code.

jjnguy
  • 136,852
  • 53
  • 295
  • 323
  • You'd have to be nuts to name a custom class String. Though I guess you might just be using a library built by someone else who is nuts... – charles-allen Sep 02 '17 at 02:03
1

They both point to the same class. It doesn't matter which one you use.

Jeff LaFay
  • 12,882
  • 13
  • 71
  • 101