Click here to Skip to main content
Click here to Skip to main content

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

By , 6 Feb 2011
 
How about:
 
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)

About the Author

ZamirF
United States United States
Member
No Biography provided

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
Hint: For improved responsiveness ensure Javascript is enabled and choose 'Normal' from the Layout dropdown and hit 'Update'.
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
GeneralRe: Ah, you are correct. Thanks.protectorAspDotNetDev5 Feb '11 - 19:19 
GeneralReason for my vote of 3 Short but inefficient.memberChantiPDM21 Feb '11 - 20:15 
GeneralReason for my vote of 4 Thank'smemberashishkumar0086 Feb '11 - 5:21 
GeneralI don't see a Reverse function on string.protectorAspDotNetDev4 Feb '11 - 7:14 
GeneralRe: It's an extension method available (IEnumerable< T >.Reverse...member d@nish 5 Feb '11 - 12:06 
It's an extension method available (IEnumerable< T >.Reverse) with .Net 3.5 and higher.
GeneralReason for my vote of 3 Very nicely condensed, but it is tec...memberKschuler3 Feb '11 - 9:42 

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

Permalink | Advertise | Privacy | Mobile
Web02 | 2.6.130516.1 | Last Updated 7 Feb 2011
Article Copyright 2011 by ZamirF
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid