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. pip安装Mysql-python报错EnvironmentError: mysql_config not found

    如下图,安装Mysql-python报错EnvironmentError: mysql_config not found 经过验证,可通过以下方式解决: 从官网下载mysql安装,成功之后输入PATH ...

  2. Spring框架学习笔记(3)——SpringMVC框架

    SpringMVC框架是基于Spring框架,可以让我们更为方便的进行Web的开发,实现前后端分离 思路和原理 我们之前仿照SpringMVC定义了一个自定义MVC框架,两者的思路其实都是一样的. 建 ...

  3. springboot 集成Redis一主二从三哨兵

    1.Centos7 Redis一主二从三哨兵配置 Redis一主二从三哨兵环境搭建 2.接入过程 与集成redis单机不同的是jedis相关的配置做了修改,JedisPool换成了JedisSenti ...

  4. idea在debug模式下的启动特别慢?

    程序执行到这里时,一直卡着不动? 原因可能是在方法上打了断点导致的: 将方法上的断点去掉,点击[Done]即可.

  5. Kafka常用命令合集

    在上一篇文章<Linux安装Kafka>中,已经介绍了如何在Linux安装Kafka,以及Kafka的启动/关闭和创建发话题并产生消息和消费消息.这篇文章就介绍介绍Kafka的那些常用的命 ...

  6. 使用XAMPP配置Apache服务器反向代理

    反向代理(Reverse Proxy)方式是指以代理服务器来接受internet上的连接请求,然后将请求转发给内部网络上的服务器,并将从服务器上得到的结果返回给internet上请求连接的客户端,此时 ...

  7. C# 读取控制台的Console.Write

    一个程序去调用另一个xxx.exe的时候,需要记录下这个exe里面的console.write的输出 public static string InvokeExcute(string Command) ...

  8. Java读源码之Thread

    前言 JDK版本:1.8 阅读了Object的源码,wait和notify方法与线程联系紧密,而且多线程已经是必备知识,那保持习惯,就从多线程的源头Thread类开始读起吧.由于该类比较长,只读重要部 ...

  9. 从0开始学FreeRTOS-(列表与列表项)-3

    # FreeRTOS列表&列表项的源码解读     第一次看列表与列表项的时候,感觉很像是链表,虽然我自己的链表也不太会,但是就是感觉很像. 在`FreeRTOS`中,列表与列表项使用得非常多 ...

  10. B-概率论-熵和信息增益

    目录 熵和信息增益 一.熵(Entropy) 二.条件熵(Conditional Entropy) 三.联合熵(Joint Entropy) 四.相对熵(Relative Entropy) 4.1 相 ...