using System.Collections.Generic;
public static void Main()
var list_1 = new List<MyObject>
new MyObject{ Code = "P1", Description = "Fisk", Id = 0 },
new MyObject{ Code = "P2", Description = "Disk", Id = 1 },
new MyObject{ Code = "P3", Description = "Risk", Id = 2 },
var list_2 = new List<MyObject>
new MyObject{ Code = "P1", Description = "Fisk", Id = 0 },
new MyObject{ Code = "P2", Description = "Disk", Id = 1 },
new MyObject{ Code = "P3", Description = "Risk", Id = 2 },
var t = list_1.Equals(list_2);
var t_1 = list_1[0].Equals(list_2[0]);
var t_2 = list_1.Take(1).Equals(list_2.Take(1));
var t_3 = list_1.SequenceEqual(list_2);
Console.WriteLine("t: {0} t_1: {1} t_2: {2},t_3 {3}", t, t_1,t_2,t_3);
protected bool Equals(MyObject other)
return Id == other.Id && string.Equals(Code, other.Code) && string.Equals(Description, other.Description);
public override bool Equals(object obj)
if (ReferenceEquals(null, obj))
if (ReferenceEquals(this, obj))
if (obj.GetType() != this.GetType())
return Equals((MyObject)obj);
public override int GetHashCode()
hashCode = (hashCode * 397) ^ (Code != null ? Code.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ (Description != null ? Description.GetHashCode() : 0);
public string Description