Is Palindrome : String : Data Types C# Source Code


Custom Search

C# Source Code » Data Types » String »

 

Is Palindrome








    
 

using System;
using System.Text;

public class MainClass {
    public static bool IsPalindrome(string s) {
        int iLength, iHalfLen;
        iLength = s.Length - 1;
        iHalfLen = iLength / 2;
        for (int i = 0; i <= iHalfLen; i++) {
            if (s.Substring(i, 1) !=
                s.Substring(iLength - i, 1)) {
                return false;
            }
        }
        return true;
    }

    static void Main(string[] args) {
        string[] sa = new string[]{"level", "minim", "radar"};

        foreach (string v in sa)
            Console.WriteLine("{0}\t{1}",v, IsPalindrome(v));
    }
}

 
    
   
  
   







HTML code for linking to this page:

Follow Navioo On Twitter

C# Source Code

 Navioo Data Types
» String