Please note, this is a STATIC archive of website www.w3resource.com from 19 Jul 2022, cach3.com does not collect or store any user information, there is no "phishing" involved.
w3resource

C# Sharp Exercises: Check if a given string is a palindrome or not

C# Sharp Basic: Exercise-56 with Solution

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 Solution:

C# Sharp Code:

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"));
             
        }
}      

Sample Output:

True
False
True
False

Pictorial Presentation:

C# Sharp Exercises: Check if a given string is a palindrome or not

Flowchart:

Flowchart: C# Sharp Exercises - Check if a given string is a palindrome or not

C# Sharp Code Editor:

Improve this sample solution and post your code through Disqus

Previous: Write a C# program to find the pair of adjacent elements that has the largest product of an given array.
Next: Write a C# program to find the pair of adjacent elements that has the highest product of an given array of integers.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.