default(CancellationToken)是否等于CancellationToken.None?

问题描述:

CancellationToken.None的实现,它只是返回default(CancellationToken).但是,我没有在CancellationToken的文档中看到两者是等效的.

Looking at the implementation of CancellationToken.None, it is simply returning default(CancellationToken). However, I see no reference in CancellationToken's documentation that the two are equivalent.

我想提供这样的API,但是直到我确定它会一直有效之前,我才提供:

I'd like to offer an API like this but not until I'm sure it'll always work:

Task DoSomething(CancellationToken token = default(CancellationToken))

default(CancellationToken)是否与CancellationToken.None相同是定义的行为,还是只是实现细节?

Is it defined behavior that default(CancellationToken) is the same as CancellationToken.None, or is this just an implementation detail?

解决问题之后使用corefx,文档注释中有已更新,以使其成为有保证的功能:

After filing an issue with corefx, the documentation remarks have been updated to make this a guaranteed feature:

您还可以使用C#default(CancellationToken)语句创建一个空的取消令牌.

You can also use the C# default(CancellationToken) statement to create an empty cancellation token.