Purushottam Rathore
Is string a value type or a reference type?
By Purushottam Rathore in ASP.NET on Jan 31 2011
  • naveen G
    Feb, 2011 4

    String is reference type but really special one. When you do operation of both string values like in your example
    C = A, there is nothing in this operation simular to normal class behavior. So C doesn't have a reference of A. In that operation, a new string class is created and the value from string A is copied to string C. String C and String A are pointing in completly different memory address. That is way, when you have many string operation, for example loop and in every iteration you have a string manipulation, because of new string class generation, that operation is performance leak. In that situation it is preffered to use StringBuilder. Why, because StringBuilder doesn't create new string for any string operation.

    • 0
  • Purushottam Rathore
    Jan, 2011 31

    A string is a collection of chars and is a reference type.

    • 0


Most Popular Job Functions


MOST LIKED QUESTIONS