Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

c#
basics
string

How to convert a char array to a string in C#

Educative Answers Team

C# allows users to convert a character array (e.g., char[] arr) ​to a String.

svg viewer

Char arr[] to string

We can perform this conversion by passing the character array to a string constructor.

Consider the following syntax:

string str = new string (char_arr)

Code

In the code below, we have a character array arr that contains h e l l o. By using a built-in string​ constructor, we can convert this character array into a string.

class HelloWorld
{
    static void Main()
    {
        char[] arr={'H','e','l','l','o'};
        string str = new string (arr);
        System.Console.WriteLine(str);       
    }
}

RELATED TAGS

c#
basics
string
Copyright ©2022 Educative, Inc. All rights reserved
RELATED COURSES

View all Courses

Keep Exploring