有谁知道如何检查一个类在哈希表中是否包含完全相同的值?就像下面的示例代码一样,即使我将 item1 和 item2 设置为与哈希表中的相同,它仍然会返回“未找到”消息。
public class WebService2 : System.Web.Services.WebService
{
public class Good
{
public string item1="address";
public string item2 ="postcode";
}
[WebMethod]
public string findhome()
{
Dictionary<Color, string> hash = new Dictionary<Color, string>();
Good good = new Good();
hash.Add(new Good() { item1 = "address", item2 = "postcode" },"home");
if (hash.ContainsKey(good))
{
return (string)hash[good];
}
return "not supported";
}
}