private static string GetExtractedStringEndings() { var result = new List <string>(); var extractStrings = new Dictionary <string, int>() { { "I love C#", 2 }, { "Nakov", 4 }, { "beer", 4 }, { "Hi", 100 } }; foreach (var str in extractStrings) { try { result.Add(StringOperations.ExtractEnding(str.Key, str.Value)); } catch (ArgumentException) { Console.WriteLine("Cannot extract ending with length {0} from '{1}'!", str.Value, str.Key); } } var returnString = string.Join(" ", result); return(returnString); }