Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Determine if Two Words Are Anagrams of Each Other
//Rextester.Program.Main is the entry point for your code. Don't change it. //Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5 using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; namespace Rextester { public class Program { public static void Main(string[] args) { //Receive Words from User string word1 = "Listen"; string word2 = "Silent"; //Add optional validation of input words if needed. //..... //step 1 char[] char1 = word1.ToLower().ToCharArray(); char[] char2 = word2.ToLower().ToCharArray(); //Step 2 Array.Sort(char1); Array.Sort(char2); //Step 3 string NewWord1 = new string(char1); string NewWord2 = new string(char2); //Step 4 //ToLower allows to compare the words in same case, in this case, lower case. //ToUpper will also do exact same thing in this context if (NewWord1 == NewWord2) { Console.WriteLine("Yes! Words \"{0}\" and \"{1}\" are Anagrams", word1, word2); } else { Console.WriteLine("No! Words \"{0}\" and \"{1}\" are not Anagrams", word1, word2); } } } }
run
|
edit
|
history
|
help
0
Importent Gen_Coverent Example-1
C Triangle
Check if string is palindrome
asdxasxasd
Expand Treeview Job Entry
olution to problem #2 from projecteuler.net
Schrikkeljaar
1.3 Basics: interfaces
Test
Simple Overriding