Interviews - C# Corner

Sibeesh Venu
Write an algorithm and program to find the word is palindrome or not?
By Sibeesh Venu in .NET onOct 28 2014
  • Rahul Prajapat
    May, 2015 30

    public static bool CheckIfPalindrome(string original) { var reversed = new string(original.ToCharArray().Reverse().ToArray()); return original == reversed; }MessageBox.Show(CheckIfPalindrome("MADAM").ToString());

    • 0
  • tri_inn
    Feb, 2015 26

    very easily we can do itpublic static bool CheckIfPalindrome(string original){var reversed = new string(original.ToCharArray().Reverse().ToArray());return original == reversed;}MessageBox.Show(CheckIfPalindrome("MADAM").ToString());

    • 0
  • Sibeesh Venu
    Oct, 2014 28

    We can do it in two waysa) By using inbuild functionsstring strRev,strReal = null;Console.WriteLine("Enter the string..");strReal = Console.ReadLine();char[] tmpChar = strReal.ToCharArray();Array.Reverse(tmpChar);strRev=new string(tmpChar);if(strReal.Equals(strRev, StringComparison.OrdinalIgnoreCase)){Console.WriteLine("The string is pallindrome");}else{Console.WriteLine("The string is not pallindrome");}Console.ReadLine(); Ref : http://www.codeproject.com/Tips/153399/To-check-string-is-palindrome-or-not-in-NET-C b)Without Using inbuild functionsWhen i write the first program, the interviewer asked me to write the same by not using inbuild functionsprivate static bool chkPallindrome(string strVal){try{int min = 0;int max = strVal.Length - 1;while (true){if (min > max)return true;char minChar = strVal[min];char maxChar = strVal[max];if (char.ToLower(minChar) != char.ToLower(maxChar)){return false;}min++;max--;}}catch (Exception){throw;}} Ref : You can find out more here http://www.dotnetperls.com/palindrome

    • 0

Most Popular Companies

Most Popular Job Functions

MOST LIKED QUESTIONS