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.
partial
type and partial
member declarationsThere are numerous errors related to partial
type and partial
member declarations:
partial
' modifier can only appear immediately before 'class
', 'record
', 'struct
', 'interface
', or a method or property return type.abstract
, extern
, or partial
abstract
' modifier.class
or partial struct
method<T>
have inconsistent type parameter constraints.static
or neither may be static
.unsafe
or neither may be unsafe
out
' parameters.virtual
', 'override
', 'sealed
', 'new
', or 'extern
' modifier.virtual
, override
, sealed
, and new
modifiers.ref
return values.scoped
modifier of parameter doesn't match partial definition.field
' keyword binds to a synthesized backing field for the property. To avoid generating a synthesized backing field, and to refer to the existing member, use 'this.field
' or '@field
' instead.The following warnings can be generated for field backed properties:
[field: MaybeNull, AllowNull]
' attributes.*field
' because the other accessor is using it.The following sections explain the cause and fixes for these errors and warnings.
partial
' modifier can only appear immediately before 'class
', 'record
', 'struct
', 'interface
', or a method or property return type.Your partial type declaration can cause the compiler to emit the following warning:
class
or struct
'type'. To specify an ordering, all instance fields must be in the same declaration.For any partial type, the partial
keyword must immediately precede class
, record
, struct
, or interface
. The compiler emits an error if it appears in any other order. In addition:
class
, struct
, record class
, record struct
, readonly struct
, or readonly record struct
).partial
modifier.Some parts of the declaration aren't required to be repeated on all declarations for a type. However, if these elements are repeated on multiple partial
declarations, they must match:
public
.A primary constructor can be declared on at most one declaration for a partial type.
The compiler warns you if you have multiple fields declared in multiple files for a partial struct
type. If the layout order is important, you must declare all fields in the same file. If order doesn't matter, you can use the System.Runtime.InteropServices.StructLayoutAttribute with the LayoutKind.Auto value.
abstract
' modifier.class
or partial struct
static
or neither may be static
.unsafe
or neither may be unsafe
virtual
, override
, sealed
, and new
modifiers.ref
return values.scoped
modifier of parameter doesn't match partial definition.Partial members have two declarations. The declaration without an implementation is the declaring declaration. The declaration with the implementation is the implementing declaration. Partial members are allowed only in a partial
type. Partial members can't be abstract
. Partial members can't explicitly implement an interface. Both declarations of a partial member must have identical signatures. For example, either both or neither declarations can include the static
or unsafe
modifiers.
abstract
, extern
, or partial
method<T>
have inconsistent type parameter constraints.out
' parameters.virtual
', 'override
', 'sealed
', 'new
', or 'extern
' modifier.Certain partial
method declarations don't require an implementing declaration. That is, if the member returns void
, doesn't declare any access modifiers (including the default private
modifier), and doesn't include any of the virtual
, override
, sealed
, or new
modifiers. Otherwise, any partial method must include both the declaring and implementing declarations.
When a partial method includes an implementing declaration, both declarations must be identical. Exactly one implementing declaration can be defined.
The following errors indicate mistakes in your partial property or indexer declarations:
The following warning indicates a signature difference in the declaring and implementing declarations in a partial property:
A partial property or indexer must have both a declaring declaration and an implementing declaration. The signatures for both declarations must match. Because the declaring declaration uses the same syntax as an automatically implemented property, the implementing declaration can't be an automatically implemented property. The accessors must have at least one accessor body. Beginning in C# 13, you can use the field
keyword to declare one accessor using a concise syntax:
public partial int ImplementingDeclaration { get => field; set; }
field
' keyword binds to a synthesized backing field for the property. To avoid generating a synthesized backing field, and to refer to the existing member, use 'this.field
' or '@field
' instead.[field: MaybeNull, AllowNull]
' attributes.*field
' because the other accessor is using it.Važno
The field
keyword is a preview feature in C# 13. You must be using .NET 9 and set your <LangVersion>
element to preview
in your project file in order to use the field
contextual keyword.
You should be careful using the field
keyword feature in a class that has a field named field
. The new field
keyword shadows a field named field
in the scope of a property accessor. You can either change the name of the field
variable, or use the @
token to reference the field
identifier as @field
. You can learn more by reading the feature specification for the field
keyword.
Beginning with C# 13, the preview feature, field
backed properties allows you to access the compiler synthesized backing field for a property. CS9258 indicates that you have a variable named field
, which can be hidden by the contextual keyword field
.
CS9263 indicates that your declaring declaration includes an implementation. That implementation might be accessing the compiler synthesized backing field for that property. CS9264 indicates that the your use of field
assumes a non-nullable backing field while the property declaration is nullable. The compiler assumes both the backing field and the property have the same nullability. You need to add the [field:MaybeNull, AllowNull]
attribute to the property declaration to indicate that the field
value should be considered nullable. CS9266 indicates that one of a properties accessors uses the field
keyword, but the other uses a hand-declared backing field. The warning indicates you may have done that by accident.
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