0

I'm developing app in Xamarin.iOS to recognize faces on the photo. I'm using Cognitive Services and Windows SDK. When I send photo with two faces (which corresponds to two different persons) I receive two elements array:

var result = results[0 or 1]

I wonder how I can check if array have two elements (because in most cases I send only 1 face, so result is have one element)?

edit Maybe I will show my code:

var result1 = results[1].Candidates[0].PersonId;
var person = await fsc.GetPersonAsync(personGroupId, result);
Console.WriteLine($"Person indentified is {person.Name}");

results[] is an array where is returned faceID of recognized person. What I mean is that if I send photo with 2 faces I get return with results[0] and results[1] -> where are faceIDs of recognized persons. I would like to show to user that there are two persons on photo. But if I send photo with one face returned is array results[0].

  • I'm not familiar with the `results[0 or 1]` syntax in C#. Can you go into a little more detail on that one? – 15ee8f99-57ff-4f92-890c-b56153 Jun 22 '17 at 18:09
  • Do you really mean 2D arrays, i.e., `[ , ]`, or are you rather talking about "jagged arrays" `[][]`? –  Jun 22 '17 at 18:09
  • 1
    Maybe it's duplicated https://stackoverflow.com/questions/24642691/c-sharp-how-to-check-if-an-object-is-a-multi-dimensional-array – viktarpunko Jun 22 '17 at 18:11
  • 2
    I think the question is how to determine whether the array length is 1 or 2 – Tobbs Jun 22 '17 at 18:12
  • 2
    I don't think you really mean "two dimensional", but rather that it contains more than one element. That would be [`results.Length`](https://msdn.microsoft.com/en-us/library/system.array.length.aspx). – Leandro Jun 22 '17 at 18:13

2 Answers2

2

In order to find out how many dimensions there are, use code such as the following.

Console.WriteLine(arr.Rank);

That returns the number of dimensions. I am not familiar with the [0 or 1] syntax you have used there.

Fabulous
  • 2,393
  • 2
  • 20
  • 27
2

For a true two-dimensional array:

string[,] example1 = new string[3, 3] {{"a","b","c"},
                                       {"d","e","f"}, 
                                       {"g","h","i"} };
Console.WriteLine("Array has {0} dimensions, with {1} x {2} = {3} elements total",
                  example1.Rank,
                  example1.GetUpperBound(0) + 1,
                  example1.GetUpperBound(1) + 1,
                  example1.Length);

For a simple array with one or two elements:

string[] example2 = new string[]{"a","b"};

Console.WriteLine("Array has {0} elements.",
                  example2.Length);

For a jagged array:

string[][] example3 = new string[][]{{"a,b,c"},
                                     {"1","2","3","4"}};

Console.WriteLine("Array contains [0] arrays with [1] and [2] elements each",
                  example3.Length,
                  example3[0].Length,
                  example3[1].Length);
John Wu
  • 50,556
  • 8
  • 44
  • 80