How to get the last 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[s.Length - 1]);
            }
        }
    }
}


/*
run:

#
+
a
p
b

*/

 



answered Nov 1, 2019 by avibootz
...