gpt4 book ai didi

c# - 从组合枚举值中获取所有枚举常量的更好方法

转载 作者:行者123 更新时间:2023-11-30 14:57:50 25 4
gpt4 key购买 nike

<分区>

我正在尝试从 Type 枚举变量中获取所有枚举值:

[Flags]
enum Type
{
XML = 1,
HTML = 2,
JSON = 4,
CVS = 8
}


static void Main(string[] args)
{

Type type = Type.JSON | Type.XML;

List<Type> types = new List<Type>();

foreach (string elem in type.ToString().Split(',') )
types.Add( (Type)Enum.Parse( typeof(Type), elem.Trim() ) );

}

有更好的方法吗?

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