IMG-LOGO

How to convert char array to string in C#?

andy - 01 Apr, 2021 3028 Views 0 Comment

If you need to convert a char array to string in C#. You can use declare a new string and pass the char array in the string constructor.

See below code in C#.

char[] letterChars = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h' };
string letterString = new string(letterChars);

This is the example we run above code in C# windows console app.

using System;
using System.Collections.Generic;
namespace ConsoleApp
{
    class Program
    {
        public static void Main(string[] args)
        {
            char[] letterChars = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h' };
            string letterString = new string(letterChars);
            Console.WriteLine(string.Format("Result: {0}", letterString));
            Console.Read();
        }
    }
}

Sample Result.

Comments

There are no comments available.

Write Comment
0 characters entered. Maximum characters allowed are 1000 characters.

Related Articles

How to remove html tags from string in c#?

Sometimes you need to remove HTML tags from string to ensure there are no dangerous or malicious scripts especially when you want to store the string or data text into the database.

Free Open Source .Net CMS

Are you looking for an open source .Net CMS for your site? When we say open source it means you can get full access to the source code without having to pay a cent.