Skip to main content
 首页 » 编程设计

C# 在哈希表中查找键并收集相应的值

2024年02月06日16wuhuacong

谁能告诉我如何在哈希表中搜索特定键并将相应的值放到变量中(例如,键和值都来自 point 类)

我添加如下值:

Hashtable Hash = new Hashtable();      
Hash.Add(new Point(Po.X - 1, Po.Y), new Point(Po.X, Po.Y)); 

请您参考如下方法:

您可以使用以下内容:

Point value; 
if (Hash.ContainsKey(YourKey)) 
{ 
    value = (Point)Hash[YourKey]; 
}