简体   繁体   English

参数“#2”不能转换“System.Collections.Generic.List”<string>

[英]Argument `#2' cannot convert `System.Collections.Generic.List<string>

I'm implementing an achievement system to my game and i can not find the way to solve this error:我正在为我的游戏实施成就系统,但找不到解决此错误的方法:

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

This is my code这是我的代码

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

You are creating List<string> listStart , but you are dealing with it as with a List<Achievement> .您正在创建List<string> listStart ,但您正在像处理List<Achievement>一样处理它。 Replace this line替换这一行

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

with this one:有了这个:

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

listStart is of type List<string> but you are adding to it Achievement objects. listStartList<string>类型,但您正在向其中添加Achievement对象。 Change it to将其更改为

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 参数 1:无法从 'System.Collections.Generic.List' 转换为 'System.Collections.Generic.List' - Argument 1: cannot convert from 'System.Collections.Generic.List' to 'System.Collections.Generic.List' 无法将类型&#39;System.Collections.Generic.List&#39;隐式转换为&#39;string&#39; - Cannot implicitly convert type 'System.Collections.Generic.List' to 'string' 无法从“字符串”转换为“system.collections.generic.list” - Cannot convert from 'string' to 'system.collections.generic.list 无法隐式转换类型&#39;System.Collections.Generic.List <System.Data.DataRow> &#39;到&#39;System.Collections.Generic.List <string> &#39; - Cannot implicitly convert type 'System.Collections.Generic.List<System.Data.DataRow>' to 'System.Collections.Generic.List<string>' C#:无法隐式转换类型“System.Collections.Generic.List”<char> &#39; 到 &#39;System.Collections.Generic.List<string> &#39; - C#: Cannot implicitly convert type 'System.Collections.Generic.List<char>' to 'System.Collections.Generic.List<string>' 无法隐式转换类型&#39;System.Collections.Generic.List &lt; <anonymous type> &gt;”到“ System.Collections.Generic.List <string> &#39; - Cannot implicitly convert type 'System.Collections.Generic.List<<anonymous type>>' to 'System.Collections.Generic.List<string>' 无法隐式转换类型&#39;System.Collections.Generic.list <fooClass> &#39;到&#39;System.Collections.Generic.List <T> - Cannot Implicitly convert type 'System.Collections.Generic.list<fooClass>' to 'System.Collections.Generic.List<T> 无法隐式转换类型&#39;System.Collections.Generic.List <AnonymousType#1> &#39;到&#39;System.Collections.Generic.List - Cannot implicitly convert type 'System.Collections.Generic.List<AnonymousType#1>' to 'System.Collections.Generic.List 无法隐式转换类型&#39;System.Collections.Generic.List <MyProduct> &#39;到&#39;System.Collections.Generic.List <T> - Cannot implicitly convert type 'System.Collections.Generic.List<MyProduct>' to 'System.Collections.Generic.List<T> 如何修复“无法将类型System.Collections.Generic.List &lt;&gt;隐式转换为System.Collections.Generic.List &lt;&gt;” - How to fix 'Cannot implicitly convert type System.Collections.Generic.List<> to System.Collections.Generic.List<>'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM