Search code examples
c#linecpu-wordletter

C#: I want every letter of a word to begin in a new line


using System;

class HelloCSharp
{
     static void Main()
     {
         Console.WriteLine("Hello C#");
     }
}

I want the output to be:

H
e
l
l
o 

C
#

but every letter should start on a new line

I am new I know but I keep searching and can't find the answer. Should it be something with Environment.NewLine ?


Solution

  • Here you go:

    string str = "Hello C#"
    char[] arr = str.ToCharArray();
    
    foreach (char c in arr)
    {
        Console.WriteLine(c);
    }