0

Possible Duplicate:
What’s the difference between String and string?
When does it matter whether you use int versus Int32, or string versus String?

in visual studio when i am typing string,it shows two suggestions as

the screenshot

is both 'string' and 'String' same? Visual studio shows the same description for both.

so if they are same what is the need for keeping two different things which perform the same function?

Community
  • 1
  • 1
Aravind Bharathy
  • 1,450
  • 3
  • 14
  • 32

5 Answers5

7

Yeah there is technically no difference at all with your use of it, as this article confirms. As said in the answer, it is considered best practice if you use string.

Hope this clears it up for you!

Community
  • 1
  • 1
FrostyFire
  • 3,083
  • 3
  • 25
  • 49
4

string is nothing more than an alias for System.String.

The same holds for int being an alias for System.Int32 (see this answer).

I also agree with the general guideline of using String for static function calls such as String.Format rather than string.Format (although I prefer string.Empty), and using string for objects (string hello = "world";).

But, at this point, it's all a matter of preferences and conventions.

Community
  • 1
  • 1
Jesse Emond
  • 6,360
  • 7
  • 30
  • 36
2

Also MSDN says the same, string is just an alias for System.String. If you want to see a full map of types that are aliased in C#, you can refer here: Data Types (C# vs. Java).

Vertigo
  • 624
  • 1
  • 8
  • 24
1

Yes they are. string is just an alias of String: they have the same features and they work the same way... normally I prefer to use String because of the code synthax highlight. But they are equivalent, exactly like int is an alias of Int32 and long is an alias of Int64.

Tommaso Belluzzo
  • 21,428
  • 7
  • 63
  • 89
0

I think both are same things, because both in the same namespace. So don't get confused. You can use any of them for string representation.

qasim azam
  • 38
  • 1
  • 1
  • 5