กิจกรรม
17 มี.ค. 21 - 21 มี.ค. 10
แอปอัจฉริยะ เข้าร่วมชุด meetup เพื่อสร้างโซลูชัน AI ที่ปรับขนาดได้ตามกรณีการใช้งานจริงกับนักพัฒนาและผู้เชี่ยวชาญร่วมกัน
ลงทะเบียนตอนนี้เบราว์เซอร์นี้ไม่ได้รับการสนับสนุนอีกต่อไป
อัปเกรดเป็น Microsoft Edge เพื่อใช้ประโยชน์จากคุณลักษณะล่าสุด เช่น การอัปเดตความปลอดภัยและการสนับสนุนด้านเทคนิค
yield return
statement and iterator methodsThere are numerous errors related to the yield return
statement and iterator methods:
&
operator cannot be used on parameters or local variables in iterator methods.An iterator method must conform to several rules in C#. The compiler issues the following errors when your iterator method violates one or more of those rules:
Your iterator method must follow the following rules:
yield return
and optionally yield break
) can't also use a return
statement to return a sequence.yield return
statement must include an expression to return as part of a sequence. yield return;
isn't valid.yield return
unsafe type, such as pointers.yield return
by ref
. You must return by value.The body of an iterator method must conform to restrictions on the yield return
statement and its context. The compiler issues the following errors when your iterator violates one of these restrictions:
&
operator cannot be used on parameters or local variables in iterator methods.These errors indicate that your code violates safety rules because an iterator returns an element and resumes to generate the next element:
yield return
from a catch
or finally
clause.yield return
from a try
block with a catch clause.yield return
from an unsafe
block. The context for an iterator creates a nested safe
block within the enclosing unsafe
block.&
operator to take the address of a variable in an iterator method.Before C# 13, iterators can't contain unsafe
code (CS1629). Beginning with C# 13, this restriction is relaxed. All yield return
statements must be in a safe context, but an iterator method can contain unsafe
code.
Iterator methods have special ref safety restrictions. These rules are relaxed in C# 13:
Before C# 13, iterators couldn't declare ref
local variables. They could not declare any variables of a ref struct
type.
Beginning with C# 13, ref struct
types can be used in iterator methods, if they aren't accessed across yield return
statement. Beginning with C# 13, iterator methods can declare ref
local variables.
คำติชม .NET
.NET เป็นโครงการโอเพนซอร์ส เลือกลิงก์เพื่อให้คำติชม:
กิจกรรม
17 มี.ค. 21 - 21 มี.ค. 10
แอปอัจฉริยะ เข้าร่วมชุด meetup เพื่อสร้างโซลูชัน AI ที่ปรับขนาดได้ตามกรณีการใช้งานจริงกับนักพัฒนาและผู้เชี่ยวชาญร่วมกัน
ลงทะเบียนตอนนี้