Tuesday, 27 August 2013

How to check hashtable contains a correct class

How to check hashtable contains a correct class

Does anyone knows how to check a class matching exactly inside a
hashtable? like a example code below, even if i set item1 and item2 same
of the one in hashtable, it still return me a "not found" message.
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";
}
}

No comments:

Post a Comment