Q:

Write a C# Sharp program to create a new string with the last char added at the front and back of a given string of length 1 or more

0

Write a C# Sharp program to create a new string with the last char added at the front and back of a given string of length 1 or more

Sample Output:

dRedd
nGreenn
111

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

using System;

namespace exercises
{
  class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine(test("Red"));
            Console.WriteLine(test("Green"));
            Console.WriteLine(test("1"));
            Console.ReadLine();
        }

        public static string test(string str)
        {
            var s = str.Substring(str.Length-1);
            return s + str + s;
        }
    }
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now