gpt4 book ai didi

.net - 我可以在 Reflector 中针对我的枚举看到的公共(public) "value__"字段的目的是什么?

转载 作者:行者123 更新时间:2023-12-03 22:26:49 24 4
gpt4 key购买 nike

我正在查看我在 Reflector 中创建的枚举,并且有一个名为“value__”的公共(public)整数字段。

这个成员(member)的目的是什么?

对文档的链接或引用可以作为答案。

谷歌搜索很痛苦,因为“value__”正在返回“value”的点击量。

我已经搜索了近一个小时,只找到了下面的链接。其中大部分是不同网站上的同一篇文章。它们都展示了如何通过反射访问成员,但没有一个解释成员的用途。

  • http://powershell.com/cs/forums/p/462/599.aspx
  • http://tfl09.blogspot.com/2008/12/enums-enum-values-and-powershell.html
  • C# function that accepts an Enum item and returns the enum value (not the index)
  • http://www.mail-archive.com/dotnet@discuss.develop.com/msg02431.html

  • 更新

    下面的最后一个链接(在底部)讨论了您不能将 value__ 用作枚举值,因为它是 reserverd 但没有说明原因。

    http://www.vijaymukhi.com/documents/books/csadv/chap3.htm

    编译器错误

    error CS0076: The enumerator name 'value__' is reserved and cannot be used ... Only for an enum does it not allow us to use the reserved word value__ as it must be using the same word internally to keep track of the enum.



    更新 2

    下面的链接指向 MSDN 页面,该页面针对编译器错误,也显示“value__”是保留的。但是仍然不高兴发现成员做了什么......

    http://msdn.microsoft.com/en-us/library/e3988xhs(v=vs.71).aspx

    最佳答案

    JIT 编译器需要一个值类型的定义来描述它在装箱时的布局。它们中的大多数都被嵌入到 mscorlib 中,例如 System.Int32。 enum 关键字允许您创建新的值类型。因此,编译器必须在元数据中为其提供定义。这就是您正在查看的内容。您将看到 ToString() 使用的每个枚举成员的静态字段。以及一个存储枚举值的实例字段名 value__。关键是这只存在于枚举值的盒装版本中。

    关于.net - 我可以在 Reflector 中针对我的枚举看到的公共(public) "value__"字段的目的是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5214031/

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