How to get the first character from each string of string array in C#

1 Answer

0 votes
using System;

class Program
{
    static void Main() {
        string[] arr = {"c#", "c++", "java", "php", "vb"};

        foreach (string s in arr) {
            if (!string.IsNullOrEmpty(s)) {
                Console.WriteLine(s[0]);
            }
        }
    }
}


/*
run:

c
c
j
p
v

*/

 



answered Nov 1, 2019 by avibootz

Related questions

1 answer 169 views
1 answer 172 views
1 answer 123 views
2 answers 173 views
4 answers 322 views
2 answers 272 views
...