Here a string is taken as input and the program suppose to check whether the string is palindrome or not. Is there any way the code can be improved? Is it okay to use foreach to break the string into character.
class Program
{
static void Main(string[] args)
{
//input a string
string orginalStr = Console.ReadLine().ToLower(); ;
//call the palindrome method
Console.WriteLine(CheckPalindrome(orginalStr)
? "This is palindrome"
: "This is not palindrome");
Console.ReadKey();
}
static bool CheckPalindrome(string orginalStr)
{
//call the string reverse method
var reversedStr = ReverseString(orginalStr);
if (reversedStr.Equals(orginalStr))
return true;
return false;
}
static string ReverseString(string orginalStr)
{
string reversedStr = "";
foreach (char ch in orginalStr)
{
reversedStr = ch + reversedStr;
}
return reversedStr;
}
}