static void Main(string[] args) { Dictionary<string, char> DecryptingDict = new Dictionary<string, char>() { { "Its A", 'A' }, { "Its B", 'B' }, }; Console.Write("Enter any text: "); var text = Console.ReadLine(); var decrypted_text = Decrypted(text, DecryptingDict); } public static string Decrypted(string sourse, Dictionary<string, char> DecryptingDict) { var decrypt_text = new StringBuilder(); foreach (var elem in sourse) { if (DecryptingDict.ContainsKey(elem)) { decrypt_text.Append(DecryptingDict[elem]); } else { decrypt_text.Append(elem); } } return decrypt_text.Tostring(); } 

On this function, and specifically on the part with the foreach loop and DecryptingDict.ContainsKey (elem) decrypt_text.Append (DecryptingDict [elem], swears Visual Studio! Says that you can't convert char to string! What should I use the function to decrypt the message?

  • I wonder if this question fits under the category "Typo" ... - EvgeniyZ

1 answer 1

char is the key:

 Dictionary<char, string> DecryptingDict = new Dictionary<char, string>() { { 'A', "It's A" }, { 'B', "It's B" } };