Convert char array to string | .Net

Convert char array to string | .Net

Added by Nasir Mahmood updated on Friday, November 17, 2017

Problem:

Previously while working on a project, I need to convert array of chars to string, I shocked to use ToString() function which return System.Char[] instead of actual string.

This is small snippet which explain how to handle such situation.

Setup:

string str = "This is test";
char[] chrs = str.ToCharArray();				
				

Now if we use chrs.ToString() it will produce wrong output.

Solution:

string result = new String(chrs);				
				

Above code will generate actual result as we want.

Related Tags

About

29 Tutorials
25 Snippets
6 Products

More

Contact Us

Contact us

Stay Connected