参数"#2"无法转换"System.Collections.Generic.List<string>



我正在为我的游戏实现成就系统,但找不到解决此错误的方法:

error CS1503: Argument `#2' cannot convert `System.Collections.Generic.List<string>' expression to type  `System.Collections.Generic.List<Achievement>'

这是我的代码

public AchievementsManager( )
{
    _achievementKeeper = new Dictionary<AchievementType, int>();
    // ideally, load here previous, saved values.
    // tap = 0
    // die = 1
    // start = 12
    // score = 1231
    _achievements = new Dictionary<AchievementType, List<Achievement>>();
    List<string> listStart = new List<string>();
    listStart.Add(new Achievement() { countToUnlock = 3, isUnlocked = false, Message = "First Time Playing!" });
    listStart.Add(new Achievement() { countToUnlock = 8, isUnlocked = false, Message = "Fifth Time is the Charm?" });
    listStart.Add(new Achievement() { countToUnlock = 10, isUnlocked = false, Message = "Hello and Welcome Back!" });
    listStart.Add(new Achievement() { countToUnlock = 16, isUnlocked = false, Message = "Tapping Time!!" });
    listStart.Add(new Achievement() { countToUnlock = 50, isUnlocked = false, Message = "Perseverance Lvl 1!" });
    _achievements.Add(AchievementType.Start, listStart );
}
listStart的类型

List<string>,但您正在向其添加对象Achievement。将其更改为

List<Achievement> listStart = new List<Achievement>();

您正在创建List<string> listStart,但您正在像处理List<Achievement>一样处理它。替换此行

List<string> listStart = new List<string>();

有了这个:

List<Achievement> listStart = new List<Achievement>();

相关内容

最新更新