public static void equalsSample3() { Dictionary<IdentifierEquals, Int32> items = new Dictionary<IdentifierEquals, Int32>(); items.Add(new IdentifierEquals(1234, "AHD"), 1); items.Add(new IdentifierEquals(5678, "BHS"), 2); foreach (KeyValuePair<IdentifierEquals, Int32> pair in items) { Console.WriteLine(pair.Key + " : " + pair.Value); } // how to search eq. 1234-AHD? IdentifierEquals searchIdentifier = new IdentifierEquals(1234, "AHD"); foreach (KeyValuePair<IdentifierEquals, Int32> pair in items) { if (searchIdentifier.Equals(pair.Key)) { Console.WriteLine("Heureka!!! --> " + pair); } } // how many 1234-AHD? Console.WriteLine("Number of " + searchIdentifier + " (stock): " + items[searchIdentifier]); // modify! items[searchIdentifier] += 3; Console.WriteLine("Number of " + searchIdentifier + " after increase (stock): " + items[searchIdentifier]); }
public bool Equals(IdentifierEquals that) { if ((object)that == null) { return false; } if (that.serialNumber == this.serialNumber && that.code.Equals(this.code)) { return true; } return false; }