Q:

Write a C# program to check if a given string is a palindrome or not

0

Write a C# program to check if a given string is a palindrome or not

Sample Example:
For 'aba' the output should be true
For 'abcd' the output should be false

Sample Output:

True
False
True
False

All Answers

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

using System;
public class Example
{
   
    public static bool checkPalindrome(string inputString)
        {
          char[] c = inputString.ToCharArray();
          Array.Reverse(c);
          return new string(c).Equals(inputString);
        }
    public static void Main()
        {
             Console.WriteLine(checkPalindrome("aaa"));
             Console.WriteLine(checkPalindrome("abc"));
             Console.WriteLine(checkPalindrome("madam"));
             Console.WriteLine(checkPalindrome("1234"));
             
        }
} 

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