备忘List内元素为接口时的Contains方法

 class Program
    {
        static void Main(string[] args)
        {
            //持有接口的引用
            List<speak> lists = new List<speak>();
            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 = "";
    }

原文地址:https://www.cnblogs.com/wishFreedom/p/3029036.html