zoukankan      html  css  js  c++  java
  • Linq101-CustomSequence

     1 using System;
     2 using System.Collections.Generic;
     3 using System.Linq;
     4 
     5 namespace Linq101
     6 {
     7     class CustomSequence
     8     {
     9         public void Linq98()
    10         {
    11             int[] vectorA = { 0, 2, 4, 5, 6 };
    12             int[] vectorB = { 1, 3, 5, 7, 8 };
    13 
    14             int result = vectorA.Combine(vectorB, (a, b) => a * b).Sum();
    15             Console.WriteLine(result);
    16         }
    17     }
    18 
    19     public static class CustomSequenceOperators
    20     {
    21         public static IEnumerable<int> Combine(this IEnumerable<int> first, IEnumerable<int> second, Func<int, int, int> func)
    22         {
    23             //List<int> list=new List<int>();
    24             using (IEnumerator<int> e1 = first.GetEnumerator(), e2 = second.GetEnumerator())
    25             {
    26                 while (e1.MoveNext() && e2.MoveNext())
    27                 {
    28                     yield return func(e1.Current, e2.Current);
    29                     //list.Add(func(e1.Current, e2.Current));
    30                 }
    31             }
    32             //return list;
    33         }
    34     }
    35 }
  • 相关阅读:
    CF1442E. Black, White and Grey Tree
    CF1442D. Sum
    CF1444D. Rectangular Polyline
    arc107F
    外心与垂心关系
    CF1434E. A Convex Game
    CF1434D. Roads and Ramen
    arc106E
    arc106F
    CF704E. Iron Man
  • 原文地址:https://www.cnblogs.com/David-Huang/p/4498043.html
Copyright © 2011-2022 走看看