c# async await
Unity3D/C# 2021. 3. 10. 17:47반응형
using System;
using System.Threading.Tasks;
using System.Net.Http;
using Newtonsoft.Json;
namespace Test
{
public class User{
public string name;
}
class Program
{
static async Task Main(string[] args)
{
// await RunAsync();
await DoAsync();
}
static async Task RunAsync(){
string message = "Async";
await Task.Delay(1);
Console.WriteLine(message);
}
static async Task DoAsync()
{
using(var client = new HttpClient())
{
var r = await client.GetAsync("https://www.dotnetnote.com/api/WebApiDemo");
var c = await r.Content.ReadAsStringAsync();
Console.WriteLine(c);
var user = JsonConvert.DeserializeObject<User>(c);
Console.WriteLine(user + " , " + user.name);
}
}
}
}
반응형
'Unity3D > C#' 카테고리의 다른 글
2048 (0) | 2021.03.19 |
---|---|
IComparable.CompareTo(Object) 메서드 (0) | 2021.03.16 |
.NET의 \0(U + 0000) 과 String (0) | 2020.12.02 |
C# bitwise (0) | 2020.11.27 |
C# 확률을 적용한 랜덤값 선택하기 (cumulative) (0) | 2020.11.26 |