0

Possible Duplicate:
What’s the difference between String and string?

I have been some time working with C# and i have ever noticed any diference between both types.

String myStringAsClass;
string myStringAsStruct;

Is there any diference other than the clarification you may use on the code or convetion to use the static functions from String class and declarations from string struct?

Thank you very much!

Community
  • 1
  • 1
Noman_1
  • 473
  • 1
  • 6
  • 17
  • 1
    Duplicate question, and incorrect premise. `string` is *not* a struct - it's just an alias for `System.String`. – Jon Skeet Feb 05 '13 at 09:46
  • 2
    The **only** difference between those is that `String` will require a `using System;` directive, where-as `string` is explicitly `global::System.String`, so doesn't need any directives. – Marc Gravell Feb 05 '13 at 09:47
  • please see http://stackoverflow.com/q/7074/1236044 – jbl Feb 05 '13 at 09:47
  • Well, thanks for the clarification, my own confussion then, since i was searching using struct on the keywords i didnt found the correct answer, my apoligizes – Noman_1 Feb 05 '13 at 09:49

3 Answers3

4

They are the same. They are both reference types.

System.String == string
System.Object == object
System.Int32 == int
System.Int64 == long

...etc.

Simon Whitehead
  • 63,300
  • 9
  • 114
  • 138
1

string is an alias to System.String, just as int is an alias to System.Int32.

Lloyd
  • 29,197
  • 4
  • 84
  • 98
0

There IS a difference between a class and a struct in C#. However that is irrelevant here since

String == string and both are class

So, to summarize, there is NO difference between the two, and string is a class.

Karthik T
  • 31,456
  • 5
  • 68
  • 87