0

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

I am using .Net Framework 4.0

I have a query for syntax. I can declare the string variable in two ways like below.

1. String str = null;
2. string str = null;

Somebody suggested me to go for first one. Is it the reason like looking good or any differences also ?

Community
  • 1
  • 1
Pankaj
  • 9,749
  • 32
  • 139
  • 283
  • See this previous post... http://stackoverflow.com/questions/7074/in-c-what-is-the-difference-between-string-and-string – James Sep 13 '11 at 15:55

3 Answers3

3

string is an alias for System.String (which is what your first line uses). They compile the same.

The only reason to go with one over the other is convention. Pick one and stick with it.

Justin Niessner
  • 242,243
  • 40
  • 408
  • 536
0

there is absolutly no difference : right click on the "string" on the second one and do "go to definition" and you'll end up on the definition of the first one.

My guess is they created the 2nd one for the older developer who use to use this syntax.

remi bourgarel
  • 9,231
  • 4
  • 40
  • 73
0

String is the name of the .NET Framework class (System.String). This name is the same over all languages targeting the .NET Framework (which is the reason why I prefer this syntax). string is basically a C# specific alias.

Same for Object and object.

Stephan
  • 4,187
  • 1
  • 21
  • 33