Click here to Skip to main content
15,503,491 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I found this question in an assessment form:

When a asynchronous method is executed, the code runs but nothing happens other than a compiler warning. What is most likely causing the method to not return anything?

(A) The return yield statement is missing at the end of the method.
(B) The yield keyword is missing from the method.
(C) The method is missing an await keyword in its body.
(D) The wait keyword is missing from the end of the method.


What I have tried:

This is a wierd question because the question ask for a wrong behaviour of your system. I don't know what to answer because I never experienced this. For me you cannot miss the await or wait otherwise your compiler give you an error. And the yield is not used for that purpose.

So this question is really confusing. What do you think?
Posted
Updated 3-Feb-21 0:18am

It's a poor question; confusing an "await" and a "missing return value"; and "executing" while "nothing happens" (?).

An async method will run synchronously (with a warning) if there is no await. (C)
 
Share this answer
 
Quote:
(A) The return yield statement is missing at the end of the method.
There is no such thing in C# as return yield. There is a yield return, but that's used in an iterator method. The only time you'd see that in an async method is if you're implementing an async enumerable[^] iterator. Since the question makes no mention of that, you can rule it out.
Quote:
(B) The yield keyword is missing from the method.
As above, yield only appears in iterator methods.
Quote:
(C) The method is missing an await keyword in its body.
As Gerry said, the method will run synchronously, and you will get a compiler warning. If it calls any Task-returning methods, it will potentially return before those tasks have completed.
Quote:
(D) The wait keyword is missing from the end of the method.
There is no wait keyword in C#.

By a process of elimination, the only possible correct answer is (C).
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900