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

Prodentim Probiotics Specially Designed For The Health Of Your Teeth And Gums

Instant Grammar Checker - Correct all grammar errors and enhance your writing

Teach Your Child To Read

Powerful WordPress hosting for WordPress professionals

Disclosure: My content contains affiliate links.

31,037 questions

40,793 answers

573 users

How to check if two strings are anagram (same letters different words) in C#

1 Answer

0 votes
using System; 
using System.Linq;
 
class Test { 
    public static void Main(string[] args) 
    { 
        string s1 = "dusty";
        string s1_sorted = String.Concat(s1.OrderBy(ch => ch));
        
        string s2 = "study";
        string s2_sorted = String.Concat(s2.OrderBy(ch => ch));
        
        if (s1_sorted == s2_sorted) { 
            Console.WriteLine("Anagram"); 
        } 
        else { 
            Console.WriteLine("Not Anagram"); 
        } 
    } 
}
 
 
 
/*
run:
 
Anagram
 
*/

 





answered Jan 28, 2019 by avibootz
edited Nov 10, 2021 by avibootz
...