How to convert string to array of chars in C#

1 Answer

0 votes
using System;
using System.IO;

class Program
{
    static void Main()
    {
        String str = "C-Sharp programming";
 
        char[] arr = new char[str.Length];  
 
        StringReader sr = new StringReader(str); 
        sr.Read(arr, 0, 19); 

        for (int i = 0; i < arr.Length; i++) {
            Console.Write("{0, 2}", arr[i]);
        }
        sr.Close();
    }
}


/*
run:

 C - S h a r p   p r o g r a m m i n g

*/


answered Aug 25, 2014 by avibootz
edited Apr 11, 2025 by avibootz

Related questions

...