为什么System.Net.Http.HttpMethod是类而不是枚举? [英] Why is System.Net.Http.HttpMethod a class, not an enum?

查看:141
本文介绍了为什么System.Net.Http.HttpMethod是类而不是枚举?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

HttpStatusCode被实现为enum,每个可能的值都分配给其相应的HTTP状态代码(例如(int)HttpStatusCode.Ok == 200).

HttpStatusCode is implemented as an enum, with each possible value assigned to its corresponding HTTP status code (e.g. (int)HttpStatusCode.Ok == 200).

但是,HttpMethod

However, HttpMethod is implemented as a class, with static properties to get instances for the various HTTP verbs (HttpStatus.GET, HttpStatus.PUT etc). What is the rationale behind not implementing HttpMethod as an enum?

推荐答案

来自

备注

HttpMethod的最常见用法是在此类上使用静态属性之一. 但是,如果应用程序需要不同的HTTP方法值,则HttpMethod构造函数会使用应用程序指定的HTTP方法来初始化HttpMethod的新实例.

The most common usage of HttpMethod is to use one of the static properties on this class. However, if an app needs a different value for the HTTP method, the HttpMethod constructor initializes a new instance of the HttpMethod with an HTTP method that the app specifies.

用枚举当然是不可能的.

Which is of course not possible with an enum.

请参见其构造器方法属性.

这篇关于为什么System.Net.Http.HttpMethod是类而不是枚举?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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