如何从枚举数值? [英] How to get the numeric value from the Enum?

查看:145
本文介绍了如何从枚举数值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如System.Net.HttpStatusCode枚举,我想获得的HTTP状态代码,而不是HTTP状态文字
System.Net.HttpStatusCode.Forbidden的应该返回403,而不是禁止

For example System.Net.HttpStatusCode Enum , i would like to get the HTTP Status Codes instead of the HTTP Status Text System.Net.HttpStatusCode.Forbidden should return 403 instead of "Forbidden"

我怎么能提取价值?

推荐答案

对于大多数枚举的仅仅投向其中INT32的基本类型。

For the majority of Enum's simply cast to the base type which is int32.

int value = (int)System.Net.HttpStatusCode.Forbidden;

这篇关于如何从枚举数值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆