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.返回顶部 |
作者:ylbtech 出处:http://ylbtech.cnblogs.com/ 本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。 |
来源:oschina
链接:https://my.oschina.net/u/4304002/blog/3222590