O'Reilly logo

Accelerated C# 2010 by Trey Nash

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 8. Working with Strings

Within the .NET Framework base class library, the System.String type is the model citizen of how to create an immutable reference type that semantically acts like a value type.

String Overview

Instances of String are immutable in the sense that once you create them, you cannot change them. Although it may seem inefficient at first, this approach actually does make code more efficient. If you call the ICloneable.Clone method on a string, you get an instance that points to the same string data as the source. In fact, ICloneable.Clone simply returns a reference to this. This is entirely safe because the String public interface offers no way to modify the actual String data. Sure, you can subvert the system by employing ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required