namespace Anagram
{
using System;
using Classes;
class MainClass
{
static void Main()
{
var Words = WordsRetriever.Retrieve();
for (var i = 0; i < Words.GetLength(0); i++)
{
App.Run(Words[i, 0], Words[i, 1]);
}
}
}
}
namespace Anagram.Classes
{
using System;
public class App
{
private static readonly string OutputTemplate = "The words {0} and {1} {2} anagrams";
public static void Run(string firstWord, string secondWord)
{
var isAnagram = AnagramChecker.IsAnagram(firstWord, secondWord);
var resultText = isAnagram ? "are" : "are not";
Console.WriteLine(OutputTemplate, firstWord, secondWord, resultText);
}
}
}
namespace Anagram.Classes
{
using System;
using System.Linq;
public class AnagramChecker
{
public static bool IsAnagram(string firstWord, string secondWord)
{
firstWord = string.Concat(firstWord.ToLower().OrderBy(x => x));
secondWord = string.Concat(secondWord.ToLower().OrderBy(x => x));
return string.Equals(firstWord, secondWord);
}
}
}
namespace Anagram.Classes
{
public class WordsRetriever
{
public static string [,] Retrieve()
{
string [,] words =
{
{"loop", "pool"},
{"rat", "art"},
{"food", "woof"}
};
return words;
}
}
}