I was going through some code to learn how to Consume a web API.
public async Task<List<TodoItem>> RefreshDataAsync ()
{
// RestUrl = http://developer.xamarin.com:8081/api/todoitems/
var uri = new Uri (string.Format (Constants.RestUrl, string.Empty));
var response = await client.GetAsync (uri);
if (response.IsSuccessStatusCode) {
var content = await response.Content.ReadAsStringAsync ();
Items = JsonConvert.DeserializeObject <List<TodoItem>> (content);
}
}
I found this code.All i want to know is why we use Async and Await. As i observed Await is mandatory in method body when function is encapsulated as Async keyword.