【发布时间】:2022-06-19 02:25:49
【问题描述】:
我目前正在使用 Unity 和 C# 进行编程,但在使用字典将字符串值链接到函数时遇到问题。
我想到了这样的代码:
private string name;
void function1()
{
// code
}
private Dictionary<string, ?function?> nameToFunction = new Dictionary<string, ?function?>();
// The part between interrogation marks being unknown to me
// Trying to call the function with the name
nameToFunction[name]
如果我的问题不是相对的,或者我没有想到更简单的解决方案,我很抱歉,但我正在开始学习编程。
感谢您的回答!
【问题讨论】:
-
这能回答你的问题吗? C# Store functions in a Dictionary
-
...添加到 Yong 的精细链接,以防链接的标题具有欺骗性,请注意作者在接受的 答案中的最后一点“如果您的函数没有返回值使用
System.Action<>"