0

Possible Duplicate:
In C#, why is String a reference type that behaves like a value type?

Why in C# string is a class/ref type , where as int/double are value/struct- any specific reason or it is by design

Community
  • 1
  • 1
user498432
  • 645
  • 3
  • 8
  • 11
  • 3
    That's a duplicate of [In C#, why is String a reference type that behaves like a value type?](http://stackoverflow.com/questions/636932/in-c-why-is-string-a-reference-type-that-behaves-like-a-value-type). Short answer: we'd like it to be a value type, but it needs to be allocated on the heap because its size can be huge. – Frédéric Hamidi Nov 20 '10 at 15:38

1 Answers1

0

Integral types have the important property of being accessible as a whole by the processor in one go. It is not the case for a string which may be composed of thousands of bytes, so in all languages, strings have always been pointed to, because the computer cannot really do it any other way.
In an object language like C#, it is canonical to create a class to point to a memory location: that's actually what an object is about.

So yes, strings are classes, because they can't be integral types.

Jean
  • 10,545
  • 2
  • 31
  • 31