This shows you the differences between two versions of the page.
Both sides previous revision Previous revision | |||
notes:csharp:tasks [2018/01/22] leszek |
notes:csharp:tasks [2018/02/22] (current) leszek |
||
---|---|---|---|
Line 21: | Line 21: | ||
Example: Return a collection from an asynchronous method GetNamesAsync: | Example: Return a collection from an asynchronous method GetNamesAsync: | ||
<code csharp> | <code csharp> | ||
- | // Method #1 | ||
var names = await GetNamesAsync(); | var names = await GetNamesAsync(); | ||
- | ... | + | </code> |
+ | |||
+ | <code csharp> | ||
+ | // Method #1 | ||
+ | public async Task<List<string>> GetNamesAsync() | ||
+ | { | ||
+ | await Task.Yield(); | ||
+ | return new List<string>() | ||
+ | { | ||
+ | "AAA", | ||
+ | "BBB", | ||
+ | "CCC" | ||
+ | }; | ||
+ | } | ||
+ | </code> | ||
+ | |||
+ | <code csharp> | ||
+ | // Method #2 | ||
public Task<List<string>> GetNamesAsync() | public Task<List<string>> GetNamesAsync() | ||
{ | { | ||
Line 38: | Line 54: | ||
<code csharp> | <code csharp> | ||
- | // Method #2 | + | // Method #3 |
- | var names = await GetNamesAsync(); | + | |
- | ... | + | |
public Task<List<string>> GetNamesAsync() | public Task<List<string>> GetNamesAsync() | ||
{ | { | ||
Line 52: | Line 66: | ||
<code csharp> | <code csharp> | ||
- | // Method #3 | + | // Method #4 |
- | var names = await GetNamesAsync(); | + | |
- | ... | + | |
public async Task<List<string>> GetNamesAsync() | public async Task<List<string>> GetNamesAsync() | ||
{ | { |