exam questions

Exam 70-487 All Questions

View all questions & answers for the 70-487 exam

Exam 70-487 topic 1 question 80 discussion

Actual exam question from Microsoft's 70-487
Question #: 80
Topic #: 1
[All 70-487 Questions]

DRAG DROP -
You have two methods named F1 and F2.
F2 takes a sting as a parameter.
You need to create a method named F3. F3 must retrieve a string value asynchronously. The string must call F2. During the asynchronous load of the string, F1 must run.
Which five code blocks should you use? Develop the solution by selecting and arranging the required code blocks in the correct order.
You will not need all of the code blocks.
NOTE:
Select and Place:

Show Suggested Answer Hide Answer
Suggested Answer:
References:
https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/concepts/async/

Comments

Chosen Answer:
This is a voting comment (?). It is better to Upvote an existing comment if you don't have anything to add.
Switch to a voting comment New
dosper
Highly Voted 5 years, 6 months ago
async Task<string> F3() { HttpClient client = new HttpClient(); Task<string> myTaskString = client.GetStringAsync("someUrl"); F1(); string urlContents = await myTaskString; return F2(urlContents); }
upvoted 57 times
MaverickCalibre
5 years, 5 months ago
This way F1() will be running and complete while we are awaiting myTaskString to complete.
upvoted 5 times
...
tiger25
5 years, 4 months ago
agreed!
upvoted 2 times
...
...
gehuki
Highly Voted 5 years, 4 months ago
async Task<string> F3() { HttpClient client = new HttpClient(); Task<string> myTaskString = client.GetStringAsync("someUrl"); string urlContents = await myTaskString; F1(); return F2(urlContents); }
upvoted 9 times
mr_
4 years, 10 months ago
This is wrong in my opinion. In that case F1() would not be running during async load of a string, but after it is loaded. Correct answer is already mentioned by dosper and Albeom.
upvoted 4 times
...
...
zimzimzimma
Most Recent 4 years, 9 months ago
The 'official answer' couldn't make less sense if they tried :/ Answers provided by dosper and albeom are correct.
upvoted 4 times
...
Albeom
5 years, 1 month ago
async Task<string> F3() { HttpClient client = new HttpClient(); Task<string> myTaskString = client.GetStringAsync("http://msdn.microsoft.com"); //start task F1(); //"during the asynchronous load of the string, F1 must run" string urlContents = await myTaskString; //get task result }
upvoted 8 times
Albeom
5 years, 1 month ago
Edit: ends with return F2(urlContents); }
upvoted 3 times
...
...
voland
5 years, 5 months ago
2nd answer is correct! reference: http://zetcode.com/csharp/httpclient/
upvoted 1 times
...
aone999
5 years, 6 months ago
2nd steps is wrong. it should be like Task<string> mytaskstring = cl.GetStringAsync("http://msdn.microsoft.com");
upvoted 4 times
...
seanlim
5 years, 6 months ago
2nd answer is wrong. http://www.herongyang.com/C-Sharp/Async-GetStringAsync-Method-Example-Program.html string uri = "http://www.herongyang.com/Service/Hello_REST.php"; HttpClient c = new HttpClient(); Task<string> t = c.GetStringAsync(uri);
upvoted 8 times
...
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.

Upvoting a comment with a selected answer will also increase the vote count towards that answer by one. So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.

SaveCancel
Loading ...