C# Distinct使用

官网Enumerable.Distinct

https://msdn.microsoft.com/zh-cn/library/bb338049.aspx

CSDN中作者oriency755

关于Distinct的使用:

http://blog.csdn.net/oriency755/article/details/13773557

使用

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Transactions;

namespace Activity
{
    public class ActivitySceneService
    {
        public List<DrawPlay> GetDraw(int activitySceneID)
        {
            using (var dbContext = new DbContext())
            {
                var merchant = dbContext.Find<Merchant>(1);
                var playList = new List<DrawPlay>();
                    playList = dbContext.Draw001Plays.Where(u => u.ActivitySceneID == activitySceneID).Distinct(
                        new Compare<DrawPlay>((x, y) => (x != null && y != null && x.UserID == y.UserID))).ToList();//放置比较器
                return playlist;
            }
        }
    }

    public delegate bool CompareDelegate<T>(T x, T y);
    public class Compare<T> : IEqualityComparer<T>
    {
        private CompareDelegate<T> _compare;
        public Compare(CompareDelegate<T> d)
        {
            this._compare = d;
        }

        public bool Equals(T x, T y)
        {
            if (_compare != null)
            {
                return this._compare(x, y);
            }
            else
            {
                return false;
            }
        }

        public int GetHashCode(T obj)
        {
            return obj.ToString().GetHashCode();
        }
    }
}

Test

时间: 2024-10-12 13:19:44

C# Distinct使用的相关文章

spark 教程三 spark Map filter flatMap union distinct intersection操作

RDD的创建 spark 所有的操作都围绕着弹性分布式数据集(RDD)进行,这是一个有容错机制的并可以被并行操作的元素集合,具有只读.分区.容错.高效.无需物化.可以缓存.RDD依赖等特征 RDD的创建基础RDD 1.并行集合(Parallelized Collections):接收一个已经存在的Scala集合,然后进行各种并行运算 var sc=new SparkContext(conf) var rdd=sc.parallelize(Array(2,4,9,3,5,7,8,1,6)); rd

mysql count distinct 统计结果去重

mysql的sql语句中,count这个关键词能统计表中的数量,如 有一个tableA表,表中数据如下: id name age 1 tony 18 2 jacky 19 3 jojo 18 SELECT COUNT(age) FROM tableA 以上这条语句能查出table表中有多少条数据.查询结果是3 而COUNT这个关键词与 DISTINCT一同使用时,可以将统计的数据中某字段不重复的数量. 如: SELECT COUNT(DISTINCT age) from tableA 以上语句的

SQL中distinct的用法

1.作用于单列 2.作用于多列 3.COUNT统计 4.distinct必须放在开头 5.其他 在表中,可能会包含重复值.这并不成问题,不过,有时您也许希望仅仅列出不同(distinct)的值.关键词 distinct用于返回唯一不同的值. 表A: 表B: 1.作用于单列 select distinct name from A 执行后结果如下: 2.作用于多列 示例2.1 select distinct name, id from A 执行后结果如下: 实际上是根据name和id两个字段来去重的

C# 中distinct的使用

假设我们有一个类:Product public class Product { public string Id { get; set; } public string Name { get; set; } } Main函数如下: static void Main() { List<Product> products = new List<Product>() { new Product(){ Id="1", Name="n1"}, new

PostgreSQL 的 distinct on 的理解

摘录自:http://www.cnblogs.com/gaojian/archive/2012/09/05/2671381.html 对于 select distinct on , 可以利用下面的例子来理解: create table a6(id integer, name varchar(10)); insert into a6 values(1, ' 001'); insert into a6 values(1, '002'); insert into a6 values(2, '003')

Distinct Subsequences

https://leetcode.com/problems/distinct-subsequences/ Given a string S and a string T, count the number of distinct subsequences of T in S. A subsequence of a string is a new string which is formed from the original string by deleting some (can be non

Oracle的去重函数 distinct

原贴地址:http://www.cnblogs.com/rainman/archive/2013/05/03/3058451.html#m0 SQL中distinct的用法 1.作用于单列 2.作用于多列 3.COUNT统计 4.distinct必须放在开头 5.其他 在表中,可能会包含重复值.这并不成问题,不过,有时您也许希望仅仅列出不同(distinct)的值.关键词 distinct用于返回唯一不同的值. 表A: 表B: 1.作用于单列 select distinct name from

LeetCode115 Distinct Subsequences

Given a string S and a string T, count the number of distinct subsequences of T in S. (Hard) A subsequence of a string is a new string which is formed from the original string by deleting some (can be none) of the characters without disturbing the re

[LeetCode] Distinct Subsequences 解题思路

Given a string S and a string T, count the number of distinct subsequences of T in S. A subsequence of a string is a new string which is formed from the original string by deleting some (can be none) of the characters without disturbing the relative

SPOJ 题目694 Distinct Substrings(后缀数组,求不同的子串个数)

DISUBSTR - Distinct Substrings no tags Given a string, we need to find the total number of its distinct substrings. Input T- number of test cases. T<=20; Each test case consists of one string, whose length is <= 1000 Output For each test case output