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

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?
New Content: Composer: Dependency manager for PHP, R Programming