Код: Выделить всё
class MyClass
{
private readonly HttpClient _client = new HttpClient();
public async Task DoWork()
{
var result = await _client.GetStringAsync("https://example.com");
Console.WriteLine(result);
}
}
< /code>
HttpClient{
private readonly HttpClient _client = new HttpClient();
public async Task DoWork()
{
var result = await _client.GetStringAsync("https://example.com");
Console.WriteLine(result);
}
public void Dispose()
{
_client.Dispose();
}
}
< /code>
What happens if I use the first snippet? Would I have a "memory leak"? Why is my IDE not complaining (Rider complains about many a thing when I code (mainly because I'm new to programming), so I was expecting it to say something)? What am I misunderstanding?
Подробнее здесь: https://stackoverflow.com/questions/797 ... of-a-class
Мобильная версия