1

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

I couldn't find the info anywhere, but I'm sure it's just a simple answer. Are they interchangeable??

Community
  • 1
  • 1
Scifiballer24
  • 593
  • 2
  • 8
  • 14
  • This question turns up on SO soooo often. And it's always, always String, even with all the numeric types, it's always String. I wonder why. – RichK Oct 09 '10 at 23:20
  • @RichK: my guess is that people probably see `string` and `String` somewhat frequently in code while `Int32` and `Int64` are rarer (`Boolean` even more so). – Chris Schmich Oct 09 '10 at 23:23

2 Answers2

8

Yes, they are identical. string is just the C# name for a System.String, which you can also use. See MSDN:

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

It's personal preference, but I always use string over String. I guess I like the blue color over the, uh, turquoise color offered by the default syntax highlighting.

You can see the other aliases under the C# value types on MSDN (e.g. int is really System.Int32 while long is really System.Int64).

Chris Schmich
  • 29,128
  • 5
  • 77
  • 94
-1

You get this question a lot because in java there is a difference between for example Integer and int (pointer allocation). In C# there is no difference between String and string, nor there is a difference between Int32 and int etc..

Andre Haverdings
  • 847
  • 8
  • 10
  • This is wrong, as has been discussed countless times already here on StackOverflow. `string` is an alias for `System.String`, i.e. it will *always* be the framework class. `String` follows the normal lookup rules, i.e. it will use *any* class named `String` which happens to be in scope. – Jörg W Mittag Oct 10 '10 at 06:58
  • euhm.. this isn't wrong ?? any good programmer would not create their own String class (and if they must they would name it MyString or something)..And I just pointed out that in JAVA there is a difference between a primitive (int) and an object (Integer). – Andre Haverdings Oct 10 '10 at 08:37