C# check if Twitch steam is online or not

Im a bit confused now. Firstly, do you mean to do this?

if (!(r == default(RootObject)))
                {
                    
                }
                else
                {
                    return true;
                }

im not sure why but using r.data.Length == 0) gives an error on Legnth:

|Error|CS1061|‘List’ does not contain a definition for ‘Length’ and no accessible extension method ‘Length’ accepting a first argument of type ‘List’ could be found (are you missing a using directive or an assembly reference?)

I can’t even seem to get the data such r.data.type or anything else:

|Error|CS1061|‘List’ does not contain a definition for ‘id’ and no accessible extension method ‘id’ accepting a first argument of type ‘List’ could be found (are you missing a using directive or an assembly reference?)

I have done what you told me to do:

 [JsonProperty("id")] public string ID { get; set; }
    [JsonProperty("userId")] public string user_id { get; set; }
    [JsonProperty("user_name")] public string user_name { get; set; }
    [JsonProperty("game_id")] public string game_id { get; set; }
    [JsonProperty("type")] public string type { get; set; }
    [JsonProperty("title")] public string title { get; set; }
    [JsonProperty("viewer_count")] public int viewer_count { get; set; }
    [JsonProperty("datetime")] public DateTime started_at { get; set; }
    [JsonProperty("language")] public string language { get; set; }
    [JsonProperty("thumb_url")] public string thumbnail_url { get; set; }
    [JsonProperty("tag_ids")] public List<string> tag_ids { get; set; }
}

public class Pagination
{
    public string cursor { get; set; }
}

public class RootObject
{
    public List<Datum> data { get; set; }
    public Pagination pagination { get; set; }
}

Doesn’t seem to work.

Here is rest of the code as well if you want to see.

static HttpClientHandler hcHandle = new HttpClientHandler();

    static async Task<bool> IsOnline(string channel)
    {
        using (var hc = new HttpClient(hcHandle, false))
        // false here prevents disposing the handler, which should live for the duration of the program and be shared by all requests that use the same handler properties
        {
            hc.DefaultRequestHeaders.Add("Client-ID", "51dn565kyrjdvphqwhxvi1agfgq3mn");
            //hc.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", "your oauth token, should you have one (you should, but not required)");
            //hc.DefaultRequestHeaders.UserAgent.ParseAdd("this would be good practice to set to your own");
            hc.Timeout = TimeSpan.FromSeconds(15); // good idea to set to something reasonable

            using (var response = await hc.GetAsync($"https://api.twitch.tv/helix/streams?user_login={channel}"))
            {
                response.EnsureSuccessStatusCode(); // throws, if fails, can check response.StatusCode yourself if you prefer
                string jsonString = await response.Content.ReadAsStringAsync();
                // TODO: parse json and return true, if the returned array contains the stream
                var r = JsonConvert.DeserializeObject<RootObject>(jsonString);

                if (!(r == default(RootObject)))
                {
                    
                }
                else
                {
                    return true;
                }

            }
        }
        return false;
    }
    

    public async void button1_Click(object sender, EventArgs e)
    {
        bool is_valid = await IsOnline("Tumblurr");
        if(is_valid == false)
        {
            MessageBox.Show("stream is offline");
        }
        else
        {
            MessageBox.Show("stream is online");
        }
       
    }

Really appreiciate your help. I’m pretty new to API and JSON things. So Thanks alot.