Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace ConsoleApplication1
- {
- class Program
- {
- static void Main(string[] args)
- {
- List<Item> l = new List<Item>()
- {
- new Item("1", "2")
- };
- Console.WriteLine(l.Contains(new Item("1", "2"))); // True
- Console.WriteLine(l.IndexOf(new Item("1", "2"))); // 0
- Console.Read();
- }
- }
- public class Item
- {
- private string param1;
- private string param2;
- public Item(string p1, string p2)
- {
- this.param1 = p1;
- this.param2 = p2;
- }
- public override bool Equals(object obj)
- {
- return obj is Item
- && ((Item)obj).param1 == this.param1
- && ((Item)obj).param2 == this.param2;
- }
- public override int GetHashCode()
- {
- return param1.GetHashCode() ^ param2.GetHashCode();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment