Nika Javakhishvili
Nika Javakhishvili

Reputation: 462

How to check if dynamic array is empty?

This is my code :

  var client = new FacebookClient(token);
 dynamic result = client.Get("search?q=tbilisi&type=user", new {  });

result.data is an array, how to determine if it's an empty array. For example what i'm trying to do :

 while (true)
 {
     if (result == null)
     {
         break;
     }
     if (result.data ==  null )
     {
         break;
     }

But not woks. When result.data = [] i want to check and break while loop.

Upvotes: 0

Views: 4806

Answers (4)

Tien Dang
Tien Dang

Reputation: 83

This one works for me:

if (object == null || ((JArray)object).Count == 0) { // code }

Upvotes: 0

Alberto Monteiro
Alberto Monteiro

Reputation: 6219

while (true)
{
     if (result == null)
     {
         break;
     }
     if (result.data ==  null || !result.data.Any())
     {
         break;
     }
}

Upvotes: 1

urvish patel
urvish patel

Reputation: 1

while (result.data.length >0) { your code here }

Upvotes: 0

Backs
Backs

Reputation: 24903

var array = result.data as Facebook.JsonArray;
if (array == null || array.Count == 0)

Upvotes: 9

Related Questions