I can't find "field" listed as a C# keyword anywhere. Does anyone know the background on this?
The NonSerialized attribute marks a variable to not be serialized.
When using the BinaryFormatter or SoapFormatter classes to serialize an object, use the NonSerializedAttribute attribute to prevent a field from being serialized. For example, you can use this attribute to prevent the serialization of sensitive data.
This is necessary, for example, if you are marking an event as non-serializable. It specifies the target that the attribute applies to.
It is part of the attribute target syntax. From the specification:
attribute-target:
field
event
method
param
property
return
type
See also the documentation for NonSerializedAttribute
:
To apply the
NonSerializedAttribute
class to an event, set the attribute location to field, as shown in the following C# code.
[field:NonSerializedAttribute()]
public event ChangedEventHandler Changed;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With