
- C# Basic Tutorial
- C# - Home
- C# - Overview
- C# - Environment
- C# - Program Structure
- C# - Basic Syntax
- C# - Data Types
- C# - Type Conversion
- C# - Variables
- C# - Constants
- C# - Operators
- C# - Decision Making
- C# - Loops
- C# - Encapsulation
- C# - Methods
- C# - Nullables
- C# - Arrays
- C# - Strings
- C# - Structure
- C# - Enums
- C# - Classes
- C# - Inheritance
- C# - Polymorphism
- C# - Operator Overloading
- C# - Interfaces
- C# - Namespaces
- C# - Preprocessor Directives
- C# - Regular Expressions
- C# - Exception Handling
- C# - File I/O
- C# Advanced Tutorial
- C# - Attributes
- C# - Reflection
- C# - Properties
- C# - Indexers
- C# - Delegates
- C# - Events
- C# - Collections
- C# - Generics
- C# - Anonymous Methods
- C# - Unsafe Codes
- C# - Multithreading
- C# Useful Resources
- C# - Questions and Answers
- C# - Quick Guide
- C# - Useful Resources
- C# - Discussion
How to check if String is Palindrome using C#?
Let’s say we need to find that the following string is Palindrome or not −
str = "Level";
For that, convert the string into character array to chec each character −
char[] ch = str.ToCharArray();
Now find the reverse −
Array.Reverse(ch);
Use the Equals method to find whether the reverse is equal to original array or not −
bool res = str.Equals(rev, StringComparison.OrdinalIgnoreCase);
The following is the complete code −
Example
using System; namespace Demo { class Program { static void Main(string[] args) { string str, rev; str = "Level"; char[] ch = str.ToCharArray(); Array.Reverse(ch); rev = new string(ch); bool res = str.Equals(rev, StringComparison.OrdinalIgnoreCase); if (res == true) { Console.WriteLine("String " + str + " is a Palindrome!"); } else { Console.WriteLine("String " + str + " is not a Palindrome!"); } Console.Read(); } } }
Output
String Level is a Palindrome!
- Related Articles
- Check if a string is palindrome in C using pointers
- Python Program to Check String is Palindrome using Stack
- How to Check Whether a String is Palindrome or Not using Python?
- How to find if a string is a palindrome using Java?
- Python program to check if a string is palindrome or not
- Python program to check if a given string is number Palindrome
- C# program to check if a string is palindrome or not
- C Program to Check if a Given String is a Palindrome?
- Python program to check if the given string is vowel Palindrome
- Recursive function to check if a string is palindrome in C++
- JavaScript - Find if string is a palindrome (Check for punctuation)
- How to check Palindrome String in java?
- How to check a String for palindrome using arrays in java?
- TCP Client-Server Program to Check if a Given String is a Palindrome
- C Program to check if an array is palindrome or not using Recursion

Advertisements