【发布时间】:2019-04-13 18:27:49
【问题描述】:
我正在尝试将下面代码中的每个循环的新列表添加到字典中,但我目前正在努力解决以下错误:
无法从“void”转换为“System.Collections.Generic.List”
public class WeaponGen{
Dictionary<string, List<string>> weapons = new Dictionary <string, List<string>>();
public void WeaponGeneration(int GenerationCount)
{
Weapon weapon = new Weapon(); //this class contains basic calculation methods
weapons.Clear();
for (int i = 0; i < GenerationCount; i++)
{
string listname = "weapon" + i;
string id = Random.Range(1, 41).ToString();
List<string>[] _lists = new List<string>[GenerationCount];
_lists[i] = new List<string>();
weapons.Add(listname, _lists[i].Add(id)); //this line throws an error
weapons.Add(listname, _lists[i].Add(weapon.GetName(id))); //this line throws an error
weapons.Add(listname, _lists[i].Add(weapon.GetRarity(id))); //this line throws an error
weapons.Add(listname, _lists[i].Add(weapon.GetType(id))); //this line throws an error
weapons.Add(listname, _lists[i].Add(weapon.GetDmg(id).ToString())); //this line throws an error
weapons.Add(listname, _lists[i].Add(weapon.GetSpeed(id).ToString())); //this line throws an error
weapons.Add(listname, _lists[i].Add(weapon.GetCost(id).ToString())); //this line throws an error
}
}}
由于我在某些方面确实缺乏编码技能,因此我认为可以更好地掌握该语言的人可以帮助我。非常感谢您的每一次帮助!
【问题讨论】:
标签: c# arrays list dictionary return