zoukankan      html  css  js  c++  java
  • List:对象 Equals、Contains

    ylbtech-List:对象 Equals、Contains
    1.返回顶部
    1.1、
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Collections.Generic;
    
    namespace ConsoleApp1
    {
        class Program
        {
            static void Main(string[] args)
            {
                Person dal1 = new Person() { Id = 101, Name = "rain" , Age=10 };
                Person dal2 = new Person() { Id = 101, Name = "rain" , Age=10.0M};
                Person dal3 = new Person() { Id = 101, Name = "rain" };
                Person dal4 = new Person() { Id = 101, Name = "rain" };
                Person dal5 = new Person() { Id = 101 };
    
                List<Person> dals1 = new List<Person>();
                dals1.Add(dal1);
                dals1.Add(dal3);
    
                Console.WriteLine("{0}", dal3.Equals(dal3));
                Console.WriteLine("{0}", dal3.Equals(dal4));
                Console.WriteLine("----------------");
    
                Console.WriteLine("{0}", dals1.Contains(dal1));
                Console.WriteLine("{0}", dals1.Contains(dal2));
                Console.WriteLine("{0}", dals1.Contains(dal3));
                Console.WriteLine("----------------");
                Console.WriteLine("{0}", dals1.Contains(new Person() { Id = 101, Name = "rain" }));
                Console.WriteLine("----------------");
                Console.WriteLine("{0}", dals1.Contains(dal4));
                Console.WriteLine("{0}", dals1.Contains(dal5));
                Console.WriteLine("----------------");
                Console.WriteLine("{0}", dals1.Remove(dal1));
                Console.WriteLine("{0}", dals1.Contains(dal1));
                Console.Read();
    
            }
        }
        class Person
        {
            public int Id { get; set; }
            public string Name { get; set; }
            public decimal Age { get; set; }
        }
    }
    1.2、input
    True
    False
    ----------------
    True
    False
    True
    ----------------
    False
    ----------------
    False
    False
    ----------------
    True
    False
    2、
    2.返回顶部
     
    3.返回顶部
     
    4.返回顶部
     
    5.返回顶部
     
     
    6.返回顶部
     
    warn 作者:ylbtech
    出处:http://ylbtech.cnblogs.com/
    本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
  • 相关阅读:
    JVM类加载器
    Java类加载过程
    进程间8种通信方式详解
    SpringCloud教程(Finchley版本)-00:什么是SpringCloud
    pyinstaller打包web项目
    Type javax.xml.bind.JAXBContext not present
    Cannot execute request on any known server
    websocket原理
    falsk模板jinja2与Vue冲突解决方案
    关于springboot Error resolving template之类问题
  • 原文地址:https://www.cnblogs.com/storebook/p/12650460.html
Copyright © 2011-2022 走看看