String creation
In this chapter you will learn:
Create string from characters
The following code creates a repeating sequence of a certain char.
using System;/*from ja v a 2s . c o m*/
class Sample
{
public static void Main()
{
string s = new string('a', 5);
Console.WriteLine(s);
}
}
The output:
Create string from character array
The following code creates string from character array.
using System;/* j a v a2s.co m*/
class Sample
{
public static void Main()
{
char[] charArray = new char[] { 'j', 'a', 'v', 'a',
'2', 's', '.', 'c', 'o', 'm', };
string s = new string(charArray);
Console.WriteLine(s);
}
}
The output:
Next chapter...
What you will learn in the next chapter:
Home » C# Tutorial » String