本文介绍了在表达式之后,新表达式需要(),[]或{}的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我开始在C#WPF中学习Task和异步编程,并编写以下代码行



任务< int> GetAnswerToLife()

{



var tcs = new TaskCompletionSource< int>

//创建启动计时器在前5秒内上涨

// var timer = new timer();



var timer = new System.Timers.Timer(5000 ){AutoReset = false};

timer.Elapsed + = delegate {timer.Dispose(); tcs.SetResult(40); } b / b
返回tcs.Task;









}



但我收到错误说新表达式需要(),[ ]或{}在类型在线后



var timer = new System.Timers.Timer(5000){AutoReset = false};在var

我不知道确切的错误原因我没有找到任何解决方案。 Plz帮我解决这个问题



谢谢

Hi I start learning Task and asynchronous programming in C# WPF, and wrote following line of code

Task<int> GetAnswerToLife()
{

var tcs = new TaskCompletionSource<int>
// Create timer that fire up in first 5 second
// var timer = new timer();

var timer = new System.Timers.Timer(5000){AutoReset= false};
timer.Elapsed += delegate{timer.Dispose() ; tcs.SetResult(40); };
timer.Start();
return tcs.Task;




}

but I get error saying "A new expression requires (), [], or {} after type" on line

var timer = new System.Timers.Timer(5000){AutoReset= false}; at "var"
I don't know exact reason for error I binged that but did not find any solution. Plz help me to solve this

Thank You

推荐答案



这篇关于在表达式之后,新表达式需要(),[]或{}的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 01:44