Code Snippets

  

C# Source Code


Welcome to Dream.In.Code
Click Here
Getting C# Help is Easy!

Join 117,574 C# Programmers for FREE! Ask your question and get quick answers from experts. There are 2,072 online right now! We've got more than 500 tutorials and 2,000 snippets. Join and find out why Dream.In.Code is the #1 programming help community on the internet! Registration is fast and FREE... Join Now!




Check to see if a string is palindromic.

Returns true if a string is palindromic.

Submitted By: RodgerB
Actions:
Rating:
Views: 412

Language: C#

Last Modified: May 11, 2008
Instructions:
1) Copy and paste the function into a class.
2) Read the example on how to call the function.

Snippet


  1. /// <summary>
  2. /// Check to see if a string is palindromic.
  3. /// </summary>
  4. /// <param name="strToCheck">The string to check</param>
  5. /// <returns>True if the string is palindromic, false otherwise.</returns>
  6. public static bool isPalindromic(string strToCheck)
  7. {
  8.     for (int i = 0; i < strToCheck.Length / 2; i++)
  9.         if (!(strToCheck[i] == strToCheck[strToCheck.Length - 1 - i])) return false;
  10.  
  11.     return true;
  12. }
  13.  
  14. // Example Usage
  15.  
  16. MessageBox.Show(isPalindromic("racecar").ToString());

Copy & Paste


Comments


There are currently no comments for this snippet. Be the first to comment!

Add comment


You must be registered and logged on to </dream.in.code> to leave comments.





Live C# Help!

C# Tutorials

Reference Sheets

C# Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month