我不知道為什么這不起作用: Dictionary<string, List<GameObject>> prefabs = new Dictionary<string, List<GameObject>>(); List<GameObject> slotPrefabs = new List<GameObject>(); // yadda yadda yadda if (prefabs.ContainsKey(slot)) { prefabs[slot] = prefabs[slot].AddRange(slotPrefabs); } else { prefabs.Add(slot, slotPrefabs); }它給了我:無法將類型“void”隱式轉(zhuǎn)換為“System.Collections.Generic.List”我只想添加到字典鍵的現(xiàn)有列表(如果它已經(jīng)存在)。
1 回答

慕桂英546537
TA貢獻(xiàn)1848條經(jīng)驗(yàn) 獲得超10個(gè)贊
AddRange(slotPrefabs)
是一個(gè) void 方法,這意味著它不會(huì)返回任何值。因此您不能將其分配給變量。
所以prefabs[slot] = prefabs[slot].AddRange(slotPrefabs);
它應(yīng)該是prefabs[slot].AddRange(slotPrefabs);
- 1 回答
- 0 關(guān)注
- 150 瀏覽
添加回答
舉報(bào)
0/150
提交
取消