zoukankan      html  css  js  c++  java
  • linq Distinct 去重

    区分大小写

      public class RowComparer : IEqualityComparer<pt_registration >
        {
            CaseInsensitiveComparer myComparer = new CaseInsensitiveComparer ();
            public bool Equals(pt_registration t1, pt_registration t2)
            {
                if (myComparer.Compare(t1.emailAddress, t2.emailAddress) == 0 && myComparer.Compare(t1.firstName, t2.firstName) == 0 && myComparer.Compare(t1.lastName, t2.lastName) == 0)
                {
                    return true ;
                } else
                {
                    return false ;
                }
            }
            public int GetHashCode(pt_registration t)
            {
                return t.ToString().ToLowerInvariant().GetHashCode();
            }
        }

    不区分大小写

     public class RowComparer : IEqualityComparer<pt_registration >
        {
            public bool Equals(pt_registration t1, pt_registration t2)
            {
                return (t1.emailAddress == t2.emailAddress && t1.firstName == t2.firstName &&t1.lastName==t2.lastName);
            }
            public int GetHashCode(pt_registration t)
            {
                return t.ToString().GetHashCode();
            }
        } 

    在下边使用哦

       IEnumerable<pt_registration > distinctRows = (from n in db.pt_registrations
                                                             where n.bankID == BankID && (n.businessName == mybusiness.formal_name || n.businessName == "ALL" ) && n.timeRegistered >= Convert .ToDateTime(startDate) && n.timeRegistered < Convert .ToDateTime(endDate)
                                                             select n).ToList().Distinct(new RowComparer());
                IList<pt_registration > myRegList = distinctRows.ToList();
                GrVw_Registration.DataSource = myRegList;
                GrVw_Registration.DataBind();
  • 相关阅读:
    用户管理的设计--3.jquery的ajax实现二级联动
    用户管理的设计--2.新增用户信息实现
    用户管理的设计--1.首页查询功能实现
    使用ajax实现简单的带百分比进度条
    python && java
    es6 modules 和commonjs
    es6 promise
    CSS“隐藏”元素的几种方法的对比
    jquery extend
    html5自定义属性
  • 原文地址:https://www.cnblogs.com/0banana0/p/2949367.html
Copyright © 2011-2022 走看看