Sabari M Sabari M
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

Sabari M
Sabari M
Software Professional, India

IT professional with 15+ years of experience in Microsoft Technologies with a strong base in Microsoft .NET (C#.Net, ASP.Net MVC, ASP.NET WEB API, Webservices,...Read More

https://www.techieclues.com/profile/alagu-mano-sabari-m

Comments (0)

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