
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
C# program to check if a string is palindrome or not
To check if a string is palindrome or not, you need to first find the reverse of the string using −
Array.reverse()
After that use the equals() method to match the original string with the reversed. If the result is true, that would mean the string is Palindrome.
Example
Let us try the complete example. Here, our string is “Malayalam”, which is when reversed gives the same result.
using System; namespace palindromecheck { class Program { static void Main(string[] args) { string string1, rev; string1 = "Malayalam"; char[] ch = string1.ToCharArray(); Array.Reverse(ch); rev = new string(ch); bool b = string1.Equals(rev, StringComparison.OrdinalIgnoreCase); if (b == true) { Console.WriteLine("" + string1 + " is a Palindrome!"); } else { Console.WriteLine(" " + string1 + " is not a Palindrome!"); } Console.Read(); } } }
Output
Malayalam is a Palindrome!
- Related Questions & Answers
- Python program to check if a string is palindrome or not
- C Program to check if an Array is Palindrome or not
- Write a C# program to check if a number is Palindrome or not
- Program to check a string is palindrome or not in Python
- Recursive program to check if number is palindrome or not in C++
- C# program to check if string is panagram or not
- C Program to check if an array is palindrome or not using Recursion
- C++ Program to Check Whether a Number is Palindrome or Not
- C program to check if a given string is Keyword or not?
- C Program to Check if a Given String is a Palindrome?
- Check if any anagram of a string is palindrome or not in Python
- Program to check if an Array is Palindrome or not using STL in C++
- Java Program to check if a string is empty or not
- Python Program to Check Whether a String is a Palindrome or not Using Recursion
- Queries to check if substring[L…R] is palindrome or not in C++ Program
Advertisements