少有人走的路

勇哥的工业自动化技术网站

本站视觉相关教程整理贴子,持续更新

2020年勇哥的机器视觉实验项目清单(大纲)

勇哥的免费视频教程清单

勇哥在B站发布的视频清单

勇哥谈下去除List的重复元素的问题

勇哥注:

去除List的重复元素的问题是比较常见的需求,C#有标准的做法,以后不要自己写了。


    public class Student
    {
        public string Name { get; private set; }
        public int Id { get; private set; }
        public string Hobby { get; private set; }
        public Student(string name, int id, string hobby)
        {
            this.Name = name;
            this.Id = id;
            this.Hobby = hobby;
        }
        /// <summary>
        /// 方便输出,重写ToString方法
        /// </summary>
        /// <returns></returns>
        public override string ToString()
        {
            return string.Format("{0}\t{1}\t{2}", this.Name, this.Id, this.Hobby);
        }
    }

    public class Compare : IEqualityComparer<Student>
    {
        public bool Equals(Student x, Student y)
        {
            return x.Id == y.Id;//可以自定义去重规则,此处将Id相同的就作为重复记录,不管学生的爱好是什么
        }
        public int GetHashCode(Student obj)
        {
            return obj.Id.GetHashCode();
        }
    }
<< 1 >>
«    2023年3月    »
12345
6789101112
13141516171819
20212223242526
2728293031
控制面板
您好,欢迎到访网站!
  查看权限
网站分类
搜索
最新留言
文章归档
网站收藏
友情链接

Powered By Z-BlogPHP 1.7.3

Copyright www.skcircle.com Rights Reserved.

鄂ICP备18008319号


站长QQ:496103864 微信:abc496103864