zoukankan      html  css  js  c++  java
  • Customer IEnuramble Extension

    public static class IEnurambleExtension
    {
        public static IEnumerable<TSource> DistinctBy<TSource, TKey>
            (this IEnumerable<TSource> source, Func<TSource, TKey> keySelector)
        { 
            HashSet<TKey> keys = new HashSet<TKey>();
    
            foreach (TSource element in source)
                if (keys.Add(keySelector(element))) 
                    yield return element;
        }
    
        public static IEnumerable<int> DistinctByReturnIndexes<TSource, TKey>
            (this IEnumerable<TSource> source, Func<TSource, TKey> keySelector)
        {
            HashSet<TKey> keys = new HashSet<TKey>();
            int i = 0;
            foreach (TSource element in source)
            {
                if (!keys.Add(keySelector(element)))
                    yield return i;
                i++;
            }
        }
    
        public static int FirstContainsWithIndex<TSource>
            (this IEnumerable<TSource> source, Func<TSource, bool> predicate)
        {
            int i = 0;
            foreach (TSource element in source)
            {
                if (predicate(element))
                    return i;
                i++;
            }
    
            return -1;
        }
    
        public static IEnumerable<int> ContainsReturnIndexes<TSource>
            (this IEnumerable<TSource> source, Func<TSource, bool> predicate)
        {
            int i = 0;
            foreach (TSource element in source)
            {
                if (predicate(element))
                   yield return i;
                i++;
            }
        }
    
    
        public static void Print<TSource, TKey>
             (this IEnumerable<TSource> source,  Func<TSource, TKey> keySelector)
            {
                foreach (TSource element in source)
                    Console.WriteLine(keySelector(element));
            }
    }
  • 相关阅读:
    -for循环案例(下)
    for循环案例(上)
    for循环
    判断语句案例
    判断语句
    操作符优先级
    windows 下安装图片标注软件 labelling和出错解决
    tf-faster rcnn
    目标检测——Faster R-CNN 详解、Pytorch搭建、训练自己的数据集
    java idea 配置安装
  • 原文地址:https://www.cnblogs.com/yang_sy/p/3586764.html
Copyright © 2011-2022 走看看