One might envision an environment
where a government could force such rules on any commercially sold software.
In the next chapter, we??™ll cover the main facets of dealing with strings in VB and .NET.
Additionally, we??™ll cover the all-important topic of globalization.
CHAPTER 8 n EXCEPTION HANDLING 165
Working with Strings
Within the .NET Base Class Library (BCL), the System.String type is the model citizen. It
offers an ideal example 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. When you copy String instances liberally within the application, you create a new
instance that points to the same raw string data as the source instance. Even if you call the
ICloneable.Clone method on a string, you get an instance which points to the same string
data as the source. This is entirely safe because the String public interface offers no way to
modify the actual String data. If you require a string that is a deep copy of the original string,
you may call the Copy method to do so.
nNote Those of you who are familiar with common design patterns and idioms may recognize this usage
pattern as the handle/body or envelope/letter idiom.
Pages:
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282