Create string from characters

The following code creates a repeating sequence of a certain char.


using System;

class Sample
{
    public static void Main()
    {
        string s = new string('a', 5);
        Console.WriteLine(s);


    }
}

The output:


aaaaa

The following code creates string from character array.


using System;

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:


java2s.com
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.