首页 > 代码库 > List<实体类> 重复排除。重写Equals.

List<实体类> 重复排除。重写Equals.

List<实体类> 重复排除。重写Equals.

public class TempData

    {

        public string Name { get; set; }

        public string Tel { get; set; }

        public string Address { get; set; }

        public override bool Equals(object obj)

        {

            TempData td = obj as TempData;

            if (td == null)

                return false;

            return Name == td.Name &&

                Tel == td.Tel &&

                Address == td.Address;

        }

        public override int GetHashCode()

        {

            return base.GetHashCode();

        }

    }

 

            List<TempData> list;
            list.Distinct(); 

 

List<实体类> 重复排除。重写Equals.