class Program { static void Main(string[] args) { //持有接口的引用 Listlists = new List (); test te = new test() { user = new user() { name = "sa123", pwd = "123456" } }; lists.Add(te); test te2 = new test() { user = new user() { name = "sa123", pwd = "123456" } }; if (!lists.Contains(te2)) { lists.Add(te2); } Console.WriteLine(lists.Count); } } //测试用接口 interface speak { void CanSpeak(); } //实际测试类 class test : speak { public user user; public void CanSpeak() { Console.WriteLine("sd"); } } //测试实体 class user { public string name = ""; public string pwd = ""; }