我正在查看一些代码。 VS将return语句标记为Redundant control flow jump statement,建议去掉。正确的语法是什么?
private async void TokenButton_Click(object sender, RoutedEventArgs e)
{
try
{
var accountType = _settings["account_type"];
if (accountType.Equals(AccountTypeMicrosoft))
{
this.Status.Text += "The original token is good for Live. No new token is needed.\n";
}
else
{
// Get access token for the target service
if (!await GetAccessTokenForServiceAsync().ConfigureAwait(true))
{
return;
}
}
}
catch (Exception ex)
{
this.Status.Text += "Exception caught: '" + ex.Message + "'.";
this.Status.Foreground = _errorBrush;
}
}
最佳答案
删除整个 if
并将其替换为:
await GetAccessTokenForServiceAsync().ConfigureAwait(true)
您不需要检查结果,因为在任何一种情况下发生的下一件事都将是该方法的结束。
关于c# - 冗余控制流跳转语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26708375/