Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,884 questions

51,810 answers

573 users

How to check whether a string is palindrome or not in C#

4 Answers

0 votes
using System;

class Program
{
    public static string reverseString(string s) {
        char[] arr = s.ToCharArray();
         
        Array.Reverse(arr);
         
        return new string(arr);
    }
    static void Main() {
        string s = "rotator";

        if (s == reverseString(s))
             Console.Write("Palindrome");
        else
            Console.Write("Not Palindrome");
    }
}




/*
run:
 
Palindrome
 
*/

 



answered Aug 23, 2021 by avibootz
0 votes
using System;
 
class Program
{
    public static string reverseString(string s) {
        string reversed = "";
 
        for (int i = s.Length - 1; i >= 0; i--) {  
            reversed += s[i].ToString();  
        }  
          
        return reversed;
    }
    static void Main() {
        string s = "rotator";
 
        if (s == reverseString(s))
            Console.Write("Palindrome");
        else
            Console.Write("Not Palindrome");
    }
}
 
 
 
 
/*
run:
  
Palindrome
  
*/

 



answered Aug 23, 2021 by avibootz
edited Jun 20, 2023 by avibootz
0 votes
using System;
 
class Program
{
    public static bool IsPalindrome(string s) {
        for (int i = 0; i < s.Length / 2; i++) {
            if (s[i] != s[s.Length - 1 - i]) {
                return false;
            }
        }
        
        return true;
    }

    static void Main() {
        string s = "rotator";
 
        if (IsPalindrome(s))
            Console.Write("Palindrome");
        else
            Console.Write("Not Palindrome");
    }
}
 
 
 
 
/*
run:
  
Palindrome
  
*/

 



answered Jun 20, 2023 by avibootz
0 votes
using System;
using System.Linq;

class Program
{
    public static bool IsPalindrome(string s) {
        return Enumerable.SequenceEqual(s.ToCharArray(), s.ToCharArray().Reverse());
    }
    
    static void Main() {
        string s = "rotator";
 
        if (IsPalindrome(s))
             Console.Write("Palindrome");
        else
            Console.Write("Not Palindrome");
    }
}
 
 
 
 
/*
run:
  
Palindrome
  
*/

 



answered Jun 20, 2023 by avibootz

Related questions

1 answer 125 views
1 answer 154 views
1 answer 137 views
1 answer 160 views
2 answers 179 views
2 answers 210 views
...