C# 2.0学习之--Yield
来源:互联网 发布:淘宝开店要考试吗 编辑:程序博客网 时间:2024/04/30 04:22
//Copyright (C) Microsoft Corporation. All rights reserved.
using System;
using System.Collections.Generic;
using System.Text;
namespace Yield
{
class Yield
{
public static class NumberList
{
// Create an array of integers.
public static int[] ints = { 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377 };
// Define a property that returns only the even numbers.
public static IEnumerable<int> GetEven()
{
// Use yield to return the even numbers in the list.
foreach (int i in ints)
if (i % 2 == 0)
yield return i;
}
// Define a property that returns only the even numbers.
public static IEnumerable<int> GetOdd()
{
// Use yield to return only the odd numbers.
foreach (int i in ints)
if (i % 2 == 1)
yield return i;
}
}
static void Main(string[] args)
{
// Display the even numbers.
Console.WriteLine("Even numbers");
foreach (int i in NumberList.GetEven())
Console.WriteLine(i);
// Display the odd numbers.
Console.WriteLine("Odd numbers");
foreach (int i in NumberList.GetOdd())
Console.WriteLine(i);
}
}
}
csc Yield.csYield
- C# 2.0学习之--Yield
- 【C#学习】yield关键字
- C#关键字之yield
- C#关键字之yield
- C#关键字之yield(迭代器)
- C#关键字之yield(迭代器)
- C# 2.0 新特性之迭代器, Yield Return
- python学习笔记之yield
- Python 学习笔记之 -- yield
- C# yield
- C# - yield
- c# yield
- C# Yield
- c# - yield
- C# yield
- C# yield
- python学习笔记之yield使用浅析
- yield 学习
- 周末到了~周末愉快哦
- 用人的四项基本原则
- C# 2.0学习之--事件1
- C# 2.0学习之--事件2
- C# 2.0学习之--泛型
- C# 2.0学习之--Yield
- Shawn is gone
- 知不足
- 趣话星座--天蝎
- 结婚了吧,傻比了吧
- set_magic_quotes_runtime()的解释
- SoftwareSOA小组SOA解决方案文档0.2版本完成!
- 比尔盖茨给年轻人的十一点忠告
- donews 你能不能 稳定点啊!!!