我不知道为什么这不起作用:
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'隐式转换为'System.Collections.Generic.List'
我只想将其添加到字典键的现有列表中。
答案 0 :(得分:5)
cmake_minimum_required(VERSION 3.0)
project(Graphics)
add_executable(
trtangle
triangle.cpp
)
target_compile_options(trtangle PRIVATE -Wall -Wextra -pedantic)
find_package(OpenGL REQUIRED)
find_package(GLEW REQUIRED)
find_package(glfw3 3.3 REQUIRED)
target_include_directories(trtangle ${OPENGL_INCLUDE_DIRS} ${GLEW_INCLUDE_DIRS})
target_link_libraries(trtangle ${OPENGL_LIBRARIES} ${GLEW_LIBRARIES} glfw)
是一个void方法,这意味着它不会返回任何值。因此,您不能将其分配给变量。
因此,它应该是AddRange(slotPrefabs)
而不是prefabs[slot] = prefabs[slot].AddRange(slotPrefabs);