gpt4 book ai didi

c# - 枚举类型宽度?

转载 作者:塔克拉玛干 更新时间:2023-11-03 08:20:14 25 4
gpt4 key购买 nike

快速提问。枚举类型有多广泛?它们是表示枚举所需的最小宽度还是都是枚举整数?如果它们是整数,您可以更改枚举的宽度,还是每次出现都必须键入 cast?

最佳答案

(这是针对 C++ 的)

来自标准:

The underlying type of an enumeration is an integral type that can represent all the enumerator values defined in the enumeration. It is implementation-defined which integral type is used as the underlying type for an enumeration except that the underlying type shall not be larger than int unless the value of an enumerator cannot fit in an int or unsigned int. If the enumerator-list is empty, the underlying type is as if the enumeration had a single enumerator with value 0. The value of sizeof() applied to an enumeration type, an object of enumeration type, or an enumerator, is the value of sizeof() applied to the underlying type.

在 C++0x 中,您可以像下面这样定义枚举的基础类型:

enum foo : unsigned int { bar, baz };

另请注意,新的强类型枚举(“枚举类”)具有默认的基础类型 int。

关于c# - 枚举类型宽度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5545236/

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