tailieunhanh - Essential CSharp 3rd Edition_6

Tham khảo tài liệu 'essential csharp 3rd edition_6', công nghệ thông tin, kỹ thuật lập trình phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả | Iterators 639 CSharpPrimitiveTypes primitives new CSharpPrimitiveTypes foreach string primitive in primitives primitive The results of Listing appear in Output . Output object byte uint ulong float char bool ushort decimal int sbyte short long void double string The output from this listing is a listing of the C primitive Iterators and State When an iterator is first called in a foreach statement such as foreach string primitive in primitives in Listing its state is initialized within the enumerator. The iterator maintains its state as long as the foreach statement at the call site continues to execute. When you yield a value process it and resume the foreach statement at the call site the iterator continues where it left off the previous time around the loop and 1. In alpha versions of the C compiler yield was a keyword rather than a contextual keyword. However such a change could result in an incompatibility between C and C . Instead yield became a contextual keyword that must appear before return. As a result no code-breaking change occurred because C did not allow any text besides comments prior to the return keyword. Chapter 16 Building Custom Collections continues processing. When the foreach statement at the call site terminates the iterator s state is no longer saved. It is always safe to call the iterator again since the generated code never resets the state of the iterator but instead creates a new one when needed. Figure shows a high-level sequence diagram of what takes place. Remember that the MoveNext method appears on the IEnumerator T interface. MoveNext yield return byte WriteLine MoveNext yield return string WriteLine Figure Sequence Diagram with yield return Iterators 641 In Listing the foreach statement at the call site initiates a call to GetEnumerator on the CSharpPrimitiveTypes instance called primitives. Given the iterator instance referenced by iterator foreach .

TỪ KHÓA LIÊN QUAN
crossorigin="anonymous">
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.