C# : cannot implicitly convert type ‘string’ to ‘int’ error

playerInfo is of type Dictionary<string, Dictionary<string, string>>. This means that playerInfo[name][timetype] will be a string.

Your method GetName has signature public int GetName(string name, string timetype) which says that it is returning an int. However at the end of that method you have return playerInfo[name][timetype]; which means that for a method that expects you are returning an int in fact is trying to return a string. Thus the compiler tells you that it is trying to convert the string to an int but is unable to because there is no implicit conversion.

Leave a Comment