是否可以在C#中定义引用自身的泛型类型?例如。我想定义一个Dictionary ,将其类型保留为TValue(用于层次结构)。Dictionary<string, Dictionary<string, Dictionary<string, [...]>>> (adsbygoogle = window.adsbygoogle || []).push({}); 最佳答案 尝试:class StringToDictionary : Dictionary<string, StringToDictionary> { }然后您可以编写:var stuff = new StringToDictionary { { "Fruit", new StringToDictionary { { "Apple", null }, { "Banana", null }, { "Lemon", new StringToDictionary { { "Sharp", null } } } } }, };递归的一般原理:找到某种方式为递归模式命名,这样它就可以通过名称进行引用。关于c# - 递归泛型类型,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/647533/ (adsbygoogle = window.adsbygoogle || []).push({}); 10-10 04:22