zoukankan      html  css  js  c++  java
  • C#- 泛型去除重复项

      今天被这个问题纠结了好一会。如何去除重复项,我遇到的问题是,在判断是否重复的条件是有两个,一个信息来源,一个是信息标题。

      最后使用了哈希后很好的解决,感觉挺高效的。代码贴下,做一个备忘

      

            //防止群发,出现重复通知,去除重复项
            private List<UserEmail> GetNotRepeatSentingEmail(List<UserEmail> LSentingEmail)
            {
                List<UserEmail> Result = new List<UserEmail>();
                Hashtable hash = new Hashtable();
                Result.Clear();
                hash.Clear();
                for (int i = 0; i < LSentingEmail.Count; i++)
                {
                    if (!hash.ContainsKey(LSentingEmail[i].T_To) && !hash.ContainsValue(LSentingEmail[i].T_Subject))
                    {
                        hash.Add(LSentingEmail[i].T_To, LSentingEmail[i].T_Subject);
                        Result.Add(LSentingEmail[i]);
                    }
                }
                return Result;
            }

      实际,这种做法不正确,

      经实验得再改进成如下:

            //防止群发,出现重复通知,去除重复项
            private List<UserEmail> GetNotRepeatSentingEmail(List<UserEmail> LSentingEmail)
            {
                List<UserEmail> Result = new List<UserEmail>();
                Hashtable hash = new Hashtable();
                Result.Clear();
                hash.Clear();
                for (int i = 0; i < LSentingEmail.Count; i++)
                {
                    string strKeys = LSentingEmail[i].T_To + "|" + LSentingEmail[i].T_Subject;
                    if (!hash.ContainsKey(strKeys ))
                    {
                        hash.Add(strKeys,"");
                        Result.Add(LSentingEmail[i]);
                    }
                }
                return Result;
            }
  • 相关阅读:
    “fatal error: hdf5.h: 没有那个文件或目录”解决方法
    算法狗的机器学习基础
    统计:假设检验 T检验
    各种排序和数据结构算法收藏
    知乎好书--入门神经网络和机器学习
    机器学习中的数学(1)-回归(regression)、梯度下降(gradient descent)
    第八天 T3S04
    第七天 T3S03
    第六天T3S02
    T3S01
  • 原文地址:https://www.cnblogs.com/cxeye/p/3581906.html
Copyright © 2011-2022 走看看