gpt4 book ai didi

c# - 为什么我的属性声明 "field:"中需要 "[field:NonSerialized]"?

转载 作者:可可西里 更新时间:2023-11-01 03:08:07 29 4
gpt4 key购买 nike

我在任何地方都找不到列为 C# 关键字的“字段”。有谁知道这件事的背景吗?

最佳答案

这是必要的,例如,如果您将事件标记为不可序列化。它指定了该属性适用的目标。

它是属性目标语法的一部分。来自specification :

attribute-target:
field
event
method
param
property
return
type

另请参阅 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;

关于c# - 为什么我的属性声明 "field:"中需要 "[field:NonSerialized]"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2022035/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com