本文介绍了CancellationToken的默认参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些异步代码,想向其中添加 CancellationToken 。但是,在许多实现中不需要此实现,因此我想使用一个默认参数-也许 CancellationToken.None 。但是,

I have some async code that I would like to add a CancellationToken to. However, there are many implementations where this is not needed so I would like to have a default parameter - perhaps CancellationToken.None. However,

Task<x> DoStuff(...., CancellationToken ct = null)

收益率

Task<x> DoStuff(...., CancellationToken ct = CancellationToken.None)



有没有办法为<$ c提供默认值$ c> CancellationToken ?

推荐答案

事实证明,以下方法有效:

It turns out that the following works:

Task<x> DoStuff(...., CancellationToken ct = default(CancellationToken))

其中,,与 CancellationToken.None 解释相同:

这篇关于CancellationToken的默认参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-02 19:35