How to get the last char from every string in array of strings with C#

1 Answer

0 votes
using System;

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

            foreach (string s in arr)
            {
                char first_char = s[s.Length - 1];

                Console.WriteLine(first_char);
            }
        }
    }
}

/*
run:
 
#
c
+
a
    
*/

 



answered Mar 14, 2017 by avibootz
...