using System;
using System.Collections.Generic;
namespace TestEnumerable
{
public class Program
{
static void Main(string[] args)
{
int[] arr1 = { 0, 2, 3, 4, 5, 6, 7 };
foreach(int i in GetAllEvenNumber(arr1)) {
Console.WriteLine(i);
}
Console.ReadLine();
}
//返回集合中的所有偶数
public static IEnumerable<int> GetAllEvenNumber(IEnumerable<int> source)
{
foreach(int item in source)
{
if(item % 2 == 0)
yield return item;
}
}
}
}