TechieClues TechieClues
Updated date Jan 20, 2023
In this blog, we will learn how to convert a list of Characters to a string in C#

We have many methods in C# to convert a list of chars to a single string in C#, the methods are listed below,

  • Using String.Concat() Method
  • Using String.Join() Method
  • Using String Class Constructor and ToArray() Method

Using String.Concat() Method

The String.Concat() is used to concatenate the given list of characters separated by an empty string as shown below, 

using System;
using System.Collections.Generic;

namespace ConvertCharToString
{
    class Program
    {
        static void Main()
        {
            List<char> chars = new List<char> { 'X', 'Y', 'Z' };

            string str = string.Concat(chars);

            Console.WriteLine(str);

            Console.ReadKey();
        }
    }
}

 Output:

XYZ

Using String.Join() Method

The String.Join method is also used to append characters of a list to a string separated by a given delimiter. In the below example, we use the String.Join() method to convert the list of chars to a single string.

using System;
using System.Collections.Generic;

namespace ConvertCharToString
{
    class Program
    {
        static void Main()
        {
            List<char> chars = new List<char> { 'X', 'Y', 'Z' };

            string str = string.Join("", chars);
           
            Console.WriteLine(str);

            Console.ReadKey();
        }
    }
}

Output:

XYZ

Using String Class Constructor and ToArray() Method

Alternatively, we use String  class Constructor and ToArray() Method to convert the list of chars to a single string in C# as shown below,

using System;
using System.Collections.Generic;

namespace ConvertCharToString
{
    class Program
    {
        static void Main()
        {
            List<char> chars = new List<char> { 'X', 'Y', 'Z' };

            string str = new string(chars.ToArray());

            Console.WriteLine(str);

            Console.ReadKey();
        }
    }
}

 Output:

XYZ

ABOUT THE AUTHOR

TechieClues
TechieClues

I specialize in creating and sharing insightful content encompassing various programming languages and technologies. My expertise extends to Python, PHP, Java, ... For more detailed information, please check out the user profile

https://www.techieclues.com/profile/techieclues

Comments (0)

There are no comments. Be the first to comment!!!