Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CSHARP

c# palidrone

//Palindrome = word that reads the same forward as it does backward
public static void Main(string[] args)
        {
            Console.WriteLine(new Program().Pal("AsdsA"));
        }
        public bool Pal(string str) 
		{
            int end = str.Length-1;

            for (int i = 0, j = end; i < end; i++, j--)
            {
                char frontLetter = str[i];	//Char.ToLower(str[i]);
                char endLetter = str[j];	//Char.ToLower(str[i]);

                if (frontLetter != endLetter) return false;
            }   
            return true;
        }        
---------------------------------------------------------Option1

public bool Pal(string str) 
        {
            char[] rev = str.ToCharArray();
            Array.Reverse(rev);
            string reversed = new string(rev);

            //if ( str.Equals(reversed, StringComparison.OrdinalIgnoreCase)  ) return true;

            if (str.Equals(reversed)) return true;

            else return false;        
        }        
----------------------------------------------------------Option2
 
PREVIOUS NEXT
Tagged: #palidrone
ADD COMMENT
Topic
Name
3+4 =