The C# string type is an alias of the System.String class. A String object is immutable, which means we cannot change its value once we have created it. When we make a change to a string we are actually creating a new string with new contents. If we would like to modify the contents of the actual string, we use the StringBuilder class (a member of the System.Text namespace). For example, we can create a string that contains “Hello,” like this:
StringBuilder myString = new StringBuilder(“Hello,”);
We can then append it with the string “World!” by using the method Append:
myString.Append(“World!”);
We can also insert a space in the sixth place by using the method Insert:
myString.Insert(6,””);
Tuesday, March 16, 2010
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment