Distinct 实现自定义去重
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 实现自定义去重的更多相关文章
- Scarpy 起始url 自定义代理 自定义去重规则
- start_urls - 内部原理 """ scrapy引擎来爬虫中去起始的URL: 1. 调用start_requests并获取返回值 2. v = iter(返回 ...
- linq Distinct 自定义去重字段
一.定义 1.Falcon_PumpX_Equal_Comparer :类名,随便取名 2.IEqualityComparer:必须继承这个接口 3.Falcon_PumpX:需要去重的对象 4.IE ...
- distinct group by 去重查询
select * from dc_restaurants; 31 select DISTINCT (restaurant_name),id from dc_restaurants ; 31 (会按照 ...
- SQL DISTINCT 用法(去重)
现在以下数据 查有出现的TeacherId SELECT TeacherID FROM Student 结果 有重复的ID出现 确实查法: SELECT TeacherID FROM Student ...
- c++中std::set自定义去重和排序函数
c++中的std::set,是基于红黑树的平衡二叉树的数据结构实现的一种容器,因为其中所包含的元素的值是唯一的,因此主要用于去重和排序.这篇文章的目的在于探讨和分享如何正确使用std::set实现去重 ...
- mysql count distinct 统计结果去重
1.使用distinct去重(适合查询整张表的总数)有多个学校+教师投稿,需要统计出作者的总数select count(author) as total from files每个作者都投稿很多,这里有 ...
- 【C#】详解使用Enumerable.Distinct方法去重
Enumerable.Distinct 方法 是常用的LINQ扩展方法,属于System.Linq的Enumerable方法,可用于去除数组.集合中的重复元素,还可以自定义去重的规则. 有两个重载方法 ...
- Linq Enumerable.Distinct方法去重
Enumerable.Distinct 方法 是常用的LINQ扩展方法,属于System.Linq的Enumerable方法,可用于去除数组.集合中的重复元素,还可以自定义去重的规则. 有两个重载方法 ...
- .NET-list扩展方法Distinct去重
原文链接:https://blog.csdn.net/daigualu/article/details/70800012 .NET中list的扩展方法Distinct可以去掉重复的元素,分别总结默认去 ...
随机推荐
- Dungeon Master POJ-2251 三维BFS
题目链接:http://poj.org/problem?id=2251 题目大意 你被困在了一个三维的迷宫,找出能通往出口的最短时间.如果走不到出口,输出被困. 思路 由于要找最短路径,其实就是BFS ...
- 十分钟快速学会Matplotlib基本图形操作
在学习Python的各种工具包的时候,看网上的各种教程总是感觉各种方法很多很杂,参数的种类和个数也十分的多,理解起来需要花费不少的时间. 所以我在这里通过几个例子,对方法和每个参数都进行详细的解释,这 ...
- SpringBoot数据聚合(spring-boot-data-aggregator-starter)
背景 接口开发是后端开发中最常见的场景, 可能是RESTFul接口, 也可能是RPC接口. 接口开发往往是从各处捞出数据, 然后组装成结果, 特别是那些偏业务的接口. 例如, 我现在需要实现一个接口, ...
- layDate——初步使用
layui系列中layDate的使用教程网址 https://www.layui.com/laydate/ 我这里简单举例: 1.引入js <script type="text/jav ...
- linux 防火墙相关命令
1.系统命令systemctl start firewalld #启动 systemctl status firewalld #查看运行状态 systemctl stop firewalld #关闭 ...
- Scanner类的next()方法和nextLine()方法的异同点
通过一段代码就可以明白其中的奥妙!! import java.util.Scanner; public class next_nextLine { public static void main(St ...
- Shell之Glob和RE的区别
目录 Shell之Glob和RE的区别 参考 Glob RE Shell之Glob和RE的区别
- phaser学习总结之Tween详解
前言 在上一章phaser学习总结之phaser入门教程中,我们已经初步入门了phaser,并通过一个案例了解了phaser,现在我们需要对phaser中的对象进行讲解,本章需要讲解的是tween,即 ...
- 你不知道的 IDEA Debug调试小技巧
一.多线程调试断点 Intellij IDEA 的debug断点调试是有一个模式的选择的,就像下面这张图,平时我们都使用的是默认的 ALL(在Eclipse中默认是线程模式) ,这种模式我们只能将一个 ...
- Mysql高手系列 - 第19篇:mysql游标详解,此技能可用于救火
Mysql系列的目标是:通过这个系列从入门到全面掌握一个高级开发所需要的全部技能. 这是Mysql系列第19篇. 环境:mysql5.7.25,cmd命令中进行演示. 代码中被[]包含的表示可选,|符 ...