Answer Posted / benjamin janecke
String is a reference type but it behaves somewhat like a
value type. So it's a bit tricky and many developers don't
know it.
Great care should be taken when doing excessive string
manipulations with the String class. As already posted,
each String is read only and can never be changed. Thus,
every manipulation creates a new instance (and causes the
garbage collector to remove old ones) which can have a
dramatic performance impact on an application. Therefore,
always use the StringBuilder class in these scenarios,
which holds only one representation of a string in memory
and performs any changes directly to that memory block.
Btw. for those who don't belive String is a reference type,
just refer to MSDN or run ILDASM und load the mscorlib.dll
module from the .NET Framework. Then go to System.String
and u'll notice it's directly inherited from System.Object -
contrary to, for instance, the System.Byte class which is
inhertied from System.ValueType, meaning Byte is a value
type, String is not.
Is This Answer Correct ? | 36 Yes | 2 No |
Post New Answer View All Answers
Explain Apache web servers ? How can you get ASP.NET running in Apache web servers - why should you do this?
What is session authentication?
Can we store object in viewstate?
Can anyone please tell me that the question posted on this website are Sufficient for the interview with 2+ year experience in .net
What are the ways of preserving data on a Web Form in ASP.NET?
Explain client-side scripting?
How many types of cookies are there in asp.net?
How many types of controls are there in asp.net?
Who generates session id?
How many ways are there to maintain a state in .net? What is view state?
Why asp.net mvc is better than asp.net? : Asp.Net MVC
What is parse in asp.net?
Where session id is stored?
How can you handle unmanaged code exceptions in asp.net?
How information about the user's locale can be accessed?