允许将指针设置为c#字典中的值

  • 本文关键字:字典 指针 设置 c# dictionary
  • 更新时间 :
  • 英文 :


我想定义一个字典,其中键是字符串类型,值是指针。这在C#中可能吗?

class Dictionary
{
Dictionary<string, void*> hebrewWords = new Dictionary<string, void*>();
}

此代码有一个错误。

这是不可能的。根据语言规范:

pointer_type不能用作类型参数,并且类型推理(类型推理(在将类型参数推断为指针类型的泛型方法调用上失败。

我正在尝试制作一个程序,使字典中的每个单词都能将我引导到树中的另一个位置

好吧,你的树可能是这样的:

public class Node {
public Node Left { get; set; }
public Node Right { get; set; }
// or a List<Node> if your tree is not binary
public SomeType Data { get; set; }
// constructor, Equals, GetHashCode...
}

那么你的字典可以是类型

词典<字符串,节点>

最新更新