Događaj
Izgradite inteligentne aplikacije
17. mar 23 - 21. mar 23
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.
This article covers the following compiler errors and warnings:
Span<T>
because it is not an assignable variableReadOnlySpan<T>
because it may not be passed or returned by referenceint
, System.Index
, or System.Range
.ref
' field, or has type that is not valid as a type argument.foreach
statement on an inline array of type is not supportedYou declare inline arrays as a struct
type with a single field, and an attribute that specifies the length of the array. The compiler generates the following errors for invalid inline array declarations:
ref
' field, or has type that is not valid as a type argument.To fix these arrays, ensure the following are true:
struct
doesn't specify any explicit layout.struct
has a single instance field, and that instance field is not a ref
field.required
, volatile
, or readonly
modifiers.record
modifier from your inline array declaration.You access elements of an inline array in the same way as any array. The compiler emits the following errors from incorrect element access:
int
, System.Index
, or System.Range
.foreach
statement on an inline array of type is not supportedIn addition, the compiler issues the following warning when you declare an indexer:
The generated code for an inline buffer accesses the buffer memory directly, bypassing any declared indexers. Inline arrays can't be used with the foreach
statement.
The argument to the indexer must be:
int
, a System.Index
or a System.Range
.You often use System.Span<T> or System.ReadOnlySpan<T> to work with inline arrays. The compiler generates the following errors for invalid conversions:
Span<T>
because it is not an assignable variableReadOnlySpan<T>
because it may not be passed or returned by referenceThe compiler generates code that directly accesses the memory for an inline buffer. Therefore, some members aren't ever called. The compiler generates the following warnings if you write one of the members that aren't ever called:
An inline array can be implicitly converted to a Span<T>
or ReadOnlySpan<T>
to pass an inline array to methods. The compiler enforces restrictions on those conversions:
Span<T>
. If the array is readonly, you can't convert it to a writable Span<T>
. You can use ReadOnlySpan<T>
instead.Span<T>
or ReadOnlySpan<T>
for the conversion to succeed. You must either limit the context of the span, or expand the scope of the inline array.In addition, the compiler never generates calls to a Slice
method in an inline buffer. Conversion operators to convert an inline buffer to a Span
or ReadOnlySpan
aren't called. The compiler generates code to create a System.Span<T> or System.ReadOnlySpan<T> directly from the memory buffer.
Povratne informacije za .NET
.NET je projekat otvorenog koda. Izaberite vezu da biste pružili povratne informacije:
Događaj
Izgradite inteligentne aplikacije
17. mar 23 - 21. mar 23
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