本文介绍了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:

这篇关于default(CancellationToken)是否等于CancellationToken.None?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-19 06:09