Click here to Skip to main content
15,881,852 members
Articles / Programming Languages / C#
Alternative
Tip/Trick

To check string is palindrome or not in .NET (C#)

Rate me:
Please Sign up or sign in to vote.
3.50/5 (4 votes)
6 Feb 2011CPOL 11.9K   1   6
How about:public bool IsPalindrome(string stringToCheck){ char[] rev = stringToCheck.Reverse().ToArray(); return (stringToCheck.Equals(new string(rev), StringComparison.OrdinalIgnoreCase));}
How about:

C#
public bool IsPalindrome(string stringToCheck)
{
    char[] rev = stringToCheck.Reverse().ToArray();
    return (stringToCheck.Equals(new string(rev), StringComparison.OrdinalIgnoreCase));
}

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralRe: Ah, you are correct. Thanks. Pin
AspDotNetDev5-Feb-11 19:19
protectorAspDotNetDev5-Feb-11 19:19 
GeneralReason for my vote of 3 Short but inefficient. Pin
Björn Friedrich21-Feb-11 20:15
Björn Friedrich21-Feb-11 20:15 
GeneralReason for my vote of 4 Thank's Pin
ashishkumar0086-Feb-11 5:21
ashishkumar0086-Feb-11 5:21 
GeneralI don't see a Reverse function on string. Pin
AspDotNetDev4-Feb-11 7:14
protectorAspDotNetDev4-Feb-11 7:14 
GeneralRe: It's an extension method available (IEnumerable< T >.Reverse... Pin
dan!sh 5-Feb-11 12:06
professional dan!sh 5-Feb-11 12:06 
GeneralReason for my vote of 3 Very nicely condensed, but it is tec... Pin
Kschuler3-Feb-11 9:42
Kschuler3-Feb-11 9:42 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.