Introducing Radical.sh

Forget Code launches a powerful code generator for building API's

Palindrome check in C#

The program explains palindrome check for a input string.
If the string and the reverse of the string are equal then they are in palindrome.

Palindrome string examples:
MADAM
VADAV

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace ConsoleApplication1
  7. {
  8. class Program
  9. {
  10. static void Main(string[] args)
  11. {
  12. string initial = "";
  13.  
  14. Console.WriteLine("Enter a String to check for Palindrome");
  15.  
  16. string input = Console.ReadLine();
  17.  
  18. int iLength = input.Length;
  19.  
  20. if (iLength == 0)
  21. {
  22. Console.WriteLine("You did not enter the string");
  23.  
  24. }
  25.  
  26. else
  27. {
  28.  
  29. for (int j = iLength - 1; j >= 0; j--)
  30. {
  31. initial = initial + input[j];
  32. }
  33.  
  34. if (initial == input)
  35. {
  36. Console.WriteLine(input + " is palindrome");
  37. }
  38. else
  39. {
  40. Console.WriteLine(input + " is not a palindrome");
  41. }
  42.  
  43.  
  44. Console.Read();
  45. }
  46. }
  47. }
  48. }



Output:
  1. Enter a String to check for Palindrome
  2. MADAM
  3. MADAM is palindrome


  1. Enter a String to check for Palindrome
  2. RAJAN
  3. RAJAN is not a palindrome