PART I
C h a p t e r 7 :
A r r a y s a n d S t r i n g s
157
PART IPART I
Once you have created a
string
object, you can use it nearly anywhere that a quoted
string is allowed. For example, you can use a
string
object as an argument to
WriteLine( )
,
as shown in this example:
// Introduce string.
using System;
class StringDemo {
static void Main() {
char[] charray = {'A', ' ', 's', 't', 'r', 'i', 'n', 'g', '.' };
string str1 = new string(charray);
string str2 = "Another string.";
Console.WriteLine(str1);
Console.WriteLine(str2);
}
}
The output from the program is shown here:
A string.
Another string.
Operating on Strings
The
string
class contains several methods that operate on strings. Table 7-1 shows a few. The
Do'stlaringiz bilan baham: |