Q:

Write a C# Sharp program to check whether the first two characters and last two characters of a given string are same

0

Write a C# Sharp program to check whether the first two characters and last two characters of a given string are same

Sample Output:

True
False
True

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("abab"));
            Console.WriteLine(test("abcdef"));
            Console.WriteLine(test("xyzsderxy"));
            Console.ReadLine();
        }

 public static bool test(string s1) 
        {
           return s1.Substring(0, 2) == s1.Substring(s1.Length - 2);
        }
   }
}

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