争论`#2&#39;无法转换`System.Collections.Generic.List <string>

时间:2017-02-14 09:23:52

标签: c# .net

我在游戏中实施了一个成就系统,但我无法找到解决此错误的方法:

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 );
}

2 个答案:

答案 0 :(得分:1)

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

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

这一个:

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

答案 1 :(得分:1)

listStart属于List<string>类型,但您要添加Achievement个对象。将其更改为

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