gpt4 book ai didi

c# - 改变枚举的数量是一个重大变化吗?

转载 作者:太空狗 更新时间:2023-10-29 19:55:20 25 4
gpt4 key购买 nike

考虑以下代码:

public enum SomeCode
{
NIF = 0
,NIE = 1
,CIF = 2
,PAS = 3
,NIN = 4
,SSN = 5
,OTH = 5
,UKN = 6
}

OTH = 5 更改为 OTH = 7 会是一个重大更改吗?


编辑:我从不存储 int 值,只存储枚举的文本表示形式。它可以在其他 DLL 中使用,但会使用相同的存储空间。

最佳答案

这是一个重大变化,因为您正在更改公共(public) API。

使用旧值构建的库/应用程序仍将保留并使用旧值。您将需要重新编译它们。

来自 MSDN - enum (C# Reference) :

Just as with any constant, all references to the individual values of an enum are converted to numeric literals at compile time. This can create potential versioning issues as described in Constants (C# Programming Guide).

关于c# - 改变枚举的数量是一个重大变化吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3422178/

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