gpt4 book ai didi

c# - 'yield' 关键字是语法糖吗?它的实现是什么

转载 作者:太空狗 更新时间:2023-10-29 21:46:35 27 4
gpt4 key购买 nike

<分区>

Possible Duplicate:
yield statement implementation

我看过 msdn docs它说:

The yield keyword signals to the compiler that the method in which it appears is an iterator block. The compiler generates a class to implement the behavior that is expressed in the iterator block. In the iterator block, the yield keyword is used together with the return keyword to provide a value to the enumerator object.

所以这意味着 yield 关键字是一个语法糖,编译器负责生成 Iterator 的繁重工作。 (我说得对吗?)

那么这个语法糖生成的实现代码是什么。

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com