The .NET Framework String Class

The .NET Framework String Class

The String class is not a built-in data type like int or long, but part of the .NET Framework. Because String isn’t a built-in type, you have to include some files in your project before the compiler will let you use it. Any code that wants to use the String class will have to include the following two lines at the top of the source-code file:

#using <mscorlib.dll> using namespace System; 

The #using line tells the compiler to look in the file mscorlib.dll for details of the String class. Mscorlib.dll is the library file that contains the core .NET components, and you’ll meet it a lot during the course of this book. The second using line makes it easier to use certain .NET classes; just type the line in as it is for now.

The String class contains a large number of methods to simplify manipulating strings, such as Insert and Replace.


Although the String class is a very powerful class, once you initialize a String object, it is immutable: it can’t be changed after it is created. The member functions of the String class that appear to alter strings, such as Insert and Replace, actually return a new String object, which contains the modified string. This behavior makes these String class methods very inefficient when making repeated modifications to a string. If you need to make repeated changes to a string, you should use the StringBuilder class. You’ll have to include the mscorlib.dll assembly and the System::Text namespace to simplify member access.

Microsoft Visual C++  .NET(c) Step by Step
Microsoft Visual C++ .NET(c) Step by Step
ISBN: 735615675
Year: 2003
Pages: 208 © 2008-2017.
If you may any questions please contact us: