首页 > 其他 > 详细

Linq101-CustomSequence

时间:2015-05-12 18:36:32      阅读:116      评论:0      收藏:0      [点我收藏+]
 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 }

 

Linq101-CustomSequence

原文:http://www.cnblogs.com/David-Huang/p/4498043.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!