0
 public async Task<T> GetAsync(string url, int id)
        {
            var request = new HttpRequestMessage(HttpMethod.Get, url);

            var client = _clientFactory.CreateClient();
            HttpResponseMessage response = await client.SendAsync(request);

            if (response.StatusCode == HttpStatusCode.OK)
            {
                var jsonString = await response.Content.ReadAsStringAsync();
                return JsonConvert.DeserializeObject<T>(jsonString);
            }

            return null;
        }

I was just curious as to why this method that says it returns a Task of type can return a boolean variable?

Mark
  • 153
  • 2
  • 7
  • How much do you know about how [async](https://stackoverflow.com/questions/14455293/how-and-when-to-use-async-and-await) works? – gunr2171 Sep 30 '21 at 22:34
  • I'm sorry, but `return null` is not really "return a boolean variable".... You probably have typo either in the title of code - consider [edit] to fix. – Alexei Levenkov Sep 30 '21 at 22:37
  • BTW, what @Alexei is saying is that a Boolean has only two possible values, `true` and `false`. You can't return `null` as a Boolean. Your method is defined to return a `Task`. Unless `T` is constrained in a way to make it nullable, you can't return `null` for that either – Flydog57 Oct 01 '21 at 04:53

0 Answers0