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可以去掉重复的元素,分别总结默认去 ...
随机推荐
- APP自動化測試腳本3
package com.lemon.day01; import java.net.MalformedURLException; import java.net.URL; import java.uti ...
- NET Core 3.0 新姿势 将AutoFac替换内置DI
.NET Core 3.0 和 以往版本不同,替换AutoFac服务的方式有了一定的变化,在尝试着升级项目的时候出现了一些问题. 原来在NET Core 2.1时候,AutoFac返回一个 IServ ...
- 【django】form
form 组件组要功能: 生成HTML标签 验证用户数据(显示错误信息) HTML Form提交保留上次提交数据 初始化页面显示内容 1.创建Form类时,主要涉及到 [字段] 和 [插件],字段用于 ...
- redis-分片(转)
转:https://www.cnblogs.com/houziwty/p/5167075.html 分片(partitioning)就是将你的数据拆分到多个 Redis 实例的过程,这样每个实例将只包 ...
- c++中不需要显示指出struct
赫 21:48:16请教个问题赫 21:49:53类声明前对私有继承的结构,的struct定义是什么作用?类声明前对该类私有继承的结构,的struct定义是什么作用?赫 21:51:21stru ...
- Linux下查看版本信息
Linux下如何查看版本信息, 包括位数.版本信息以及CPU内核信息.CPU具体型号等. 1.# uname -a (Linux查看版本当前操作系统内核信息) 2.# cat /proc/ ...
- 玩转 SpringBoot 2 之整合 JWT 下篇
前言 在<玩转 SpringBoot 2 之整合 JWT 上篇> 中介绍了关于 JWT 相关概念和JWT 基本使用的操作方式.本文为 SpringBoot 整合 JWT 的下篇,通过解决 ...
- [Mathematics][MIT 18.03] Proof of a Theory about the Solution to Second-order Linear Homogeneous Differential Equation
At first, I'd like to say thank you to MIT open courses which give me the privilege to enjoy the mos ...
- mysql数据库设计规则总结
MySQL数据库设计总结 规则1:一般情况可以选择MyISAM存储引擎,如果需要事务支持必须使用InnoDB存储引擎. 注意:MyISAM存储引擎 B-tree索引有一个很大的限制:参与一个索引的 ...
- django的url分发封装
h2, body>h3, body>h4, body>h1{ padding: 10px; background-color: #4cae4c; text-align: center ...