首页 > 其他 > 详细

Is default(CancellationToken) equivalent to CancellationToken.None?(转载)

时间:2020-02-07 10:51:08      阅读:93      评论:0      收藏:0      [点我收藏+]


 

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.
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))

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

 

 

答1


 

They are the same. Check source code

public static CancellationToken None
{
    get { return default(CancellationToken); }
}

From https://referencesource.microsoft.com/#mscorlib/system/threading/CancellationToken.cs,36b17ded8b1a228c

 

 

答2


 

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

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

 

 

原文链接

 

Is default(CancellationToken) equivalent to CancellationToken.None?(转载)

原文:https://www.cnblogs.com/OpenCoder/p/12271724.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!