Događaj
Izgradite inteligentne aplikacije
17. mar 21 - 21. mar 10
Pridružite se seriji sastanaka kako biste izgradili skalabilna AI rešenja zasnovana na stvarnim slučajevima korišćenja sa kolegama programerima i stručnjacima.
Registrujte se odmahOvaj pregledač više nije podržan.
Nadogradite na Microsoft Edge biste iskoristili najnovije funkcije, bezbednosne ispravke i tehničku podršku.
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.
Povratne informacije za .NET
.NET je projekat otvorenog koda. Izaberite vezu da biste pružili povratne informacije:
Događaj
Izgradite inteligentne aplikacije
17. mar 21 - 21. mar 10
Pridružite se seriji sastanaka kako biste izgradili skalabilna AI rešenja zasnovana na stvarnim slučajevima korišćenja sa kolegama programerima i stručnjacima.
Registrujte se odmah