Monday, 18 May 2015

Strings

Strings
Strings are reference types but behave like value types.  They have been optimised within the .Net framework.

Checking for equality performs a string comparison, not an Object.ReferenceEquals that is normally performed when you compare two reference type variables.

When comparing two strings for equality the framework compares the sequence of characters in each string to compare if they have the same value (rather than the same object).

Strings are immutable - can't be modified.  So performing operations that appear to modify a string, such as Trim, don't.  Rather they return a new string with the result, which must be captured if you want to see the effects of the modification.  The original string remains unaltered.  It is immutable.

No comments:

Post a Comment