Mohanapriya R Mohanapriya R
Updated date Jul 23, 2024
In this article, we will learn how to convert strings to char in C#
  • 1.3k
  • 0
  • 0

Convert Strings to Char in C#:

In C#, strings are instances of the System.String class, and each character within a string can be accessed using indexing. To convert a string to characters, we can iterate through the string and extract each character one by one. Let's see the below C# program,

using System;

class Program
{
    static void Main()
    {
        // Input string
        string inputString = "Hello, TechieHook!";

        // Convert string to char array
        char[] charArray = inputString.ToCharArray();

        // Display each character
        Console.WriteLine("Individual characters from the string:");
        foreach (char character in charArray)
        {
            Console.Write(character + " ");
        }
    }
}

Output:

Individual characters from the string:
H e l l o ,   T E C H I E H O O K !

Comments (0)

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