Converting a string to an array of chars. - CSharp Language Basics

CSharp examples for Language Basics:Data Type Cast

Description

Converting a string to an array of chars.

Demo Code

using System;//w w w .  ja va 2 s.  com
using System.Text;                // Need for type UTF8Encoding.
using System.Globalization;       // Need for cultures.
class Program
{
   static void Main(string[] args)
   {
      // Converting a string to an array of chars.
      Console.WriteLine("Convert a string to an array of chars.");
      string custName = "Pam III Sphar";
      char[] custNameChars = custName.ToCharArray();
      foreach (char c in custNameChars)
      {
         Console.Write(c);
      }
   }
}

Result


Related Tutorials