using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks; namespace wpfDistinct
{
class DataCompare : IEqualityComparer<DateTime>
{ public bool Equals(DateTime x, DateTime y)
{
return x.Hour == y.Hour;
} public int GetHashCode(DateTime obj)
{
return (obj.Year + obj.Month + obj.Day + obj.Hour).ToString().GetHashCode(); }
}
}
 using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes; namespace wpfDistinct
{
/// <summary>
/// MainWindow.xaml 的交互逻辑
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent(); Random rand = new Random();
List<DateTime> list = new List<DateTime>();
for (int i = ; i < ; i++)
{
list.Add(new DateTime(, rand.Next(, ), rand.Next(, ), rand.Next(, ),rand.Next(,),rand.Next(,)));
}
if (null != list)
{
List<DateTime> list3 = list.Distinct(new DataCompare()).ToList(); if (null != list3)
{
List<List<DateTime>> collcetion = new List<List<DateTime>>();
foreach (DateTime time in list3)
{
collcetion.Add(list.Where(i => i.Month==time.Month&& i.Day == time.Day&&i.Hour==time.Hour).ToList());
}
} } }
}
}
Distinct 要实现IEqualityComparer<DateTime> 这个接口才能自定义
hashCode的精度到那个地方,就可以以那种精度进行去重

Distinct 实现自定义去重的更多相关文章

  1. Scarpy 起始url 自定义代理 自定义去重规则

    - start_urls - 内部原理 """ scrapy引擎来爬虫中去起始的URL: 1. 调用start_requests并获取返回值 2. v = iter(返回 ...

  2. linq Distinct 自定义去重字段

    一.定义 1.Falcon_PumpX_Equal_Comparer :类名,随便取名 2.IEqualityComparer:必须继承这个接口 3.Falcon_PumpX:需要去重的对象 4.IE ...

  3. distinct group by 去重查询

    select * from dc_restaurants;  31 select DISTINCT (restaurant_name),id from dc_restaurants ; 31 (会按照 ...

  4. SQL DISTINCT 用法(去重)

    现在以下数据 查有出现的TeacherId SELECT TeacherID FROM Student 结果 有重复的ID出现 确实查法: SELECT TeacherID FROM Student ...

  5. c++中std::set自定义去重和排序函数

    c++中的std::set,是基于红黑树的平衡二叉树的数据结构实现的一种容器,因为其中所包含的元素的值是唯一的,因此主要用于去重和排序.这篇文章的目的在于探讨和分享如何正确使用std::set实现去重 ...

  6. mysql count distinct 统计结果去重

    1.使用distinct去重(适合查询整张表的总数)有多个学校+教师投稿,需要统计出作者的总数select count(author) as total from files每个作者都投稿很多,这里有 ...

  7. 【C#】详解使用Enumerable.Distinct方法去重

    Enumerable.Distinct 方法 是常用的LINQ扩展方法,属于System.Linq的Enumerable方法,可用于去除数组.集合中的重复元素,还可以自定义去重的规则. 有两个重载方法 ...

  8. Linq Enumerable.Distinct方法去重

    Enumerable.Distinct 方法 是常用的LINQ扩展方法,属于System.Linq的Enumerable方法,可用于去除数组.集合中的重复元素,还可以自定义去重的规则. 有两个重载方法 ...

  9. .NET-list扩展方法Distinct去重

    原文链接:https://blog.csdn.net/daigualu/article/details/70800012 .NET中list的扩展方法Distinct可以去掉重复的元素,分别总结默认去 ...

随机推荐

  1. Linux Centos7部署环境安装-CentOS

    Linux Centos7部署环境安装-CentOS Centos7部署环境安装及Linux常用命令 centos系统下各文件夹的作用 centos7修改系统默认语言 centos7安装rz/sz命令 ...

  2. jmeter基础使用

    1.ServerAgent是服务端的插件2.下载成功后,复制JmeterPlugins-Extras.jar和JmeterPlugins-Standard.jar两个文件,放到jmeter安装文件中的 ...

  3. ubuntu linux重置密码

    (和网上的有点不一样,记录一下) 1)重启系统,同时长时间按住shift键进入grub菜单:GNU GRUB version 1.99-12ubuntu5(如图一) 2)选择Ubuntu, with ...

  4. Sentinel Cluster流程分析

     前面介绍了sentinel-core的流程,提到在进行流控判断时,会判断当前是本地限流,还是集群限流,若是集群模式,则会走另一个分支,这节便对集群模式做分析. 一.基本概念  namespace:限 ...

  5. 读《深入理解Elasticsearch》点滴-改正用户拼写错误

    1.使用“建议”的方法:在query body的json结构体中,增加suggest节点:或者使用特殊的REST端点 2.es自带有多个不同的suggest实现,用来纠正用户的拼写错误及创建自动补全等 ...

  6. linux 安装docker

    1.安装环境 此处在Centos7进行安装,可以使用以下命令查看CentOS版本 lsb_release -a 在 CentOS 7安装docker要求系统为64位.系统内核版本为 3.10 以上,可 ...

  7. 自定义属性--JavaScript

    1 - 获取属性值 element.属性 获取属性值 element.getAttribute('属性') 区别: element.属性 --获取内置属性(元素本身自带的属性) element.get ...

  8. GitHub项目徽标

    前言 GitHub徽标,GitHub Badge,你也可以叫它徽章.就是在项目README中经常看到的那些表明构建状态或者版本等信息的小图标.就像这样: 这些好看的小图标不仅简洁美观,而且包含了清晰易 ...

  9. 体验Code::Blocks下的C++编程

    0.前言 在当前的行业发展和国际形势下,让更多的程序员思考跨平台编程问题.在众多的跨平台开发环境中,Code::Blocks具有独特的优势. 近二十年来,跨平台开发环境曾经如雨后春笋般产生,但是,由于 ...

  10. Java 上传解压zip文件,并且解析文件里面的excel和图片

    需求:上传一个zip文件,zip文件里面包含一个excel和很多图片,需要把excel里面的信息解析出来保存到表中,同时图片也转化成base64保存到数据库表中. PS:为了方便不同水平的开发人员阅读 ...