-3
IDictionary<string, object> test2 = new Dictionary<string, object>
            {
                { "username", ParseUser.CurrentUser.Username}
            };

        var result = await ParseCloud.CallFunctionAsync<Object>("getShiftCount", test2);

        System.Diagnostics.Debug.Write(result);

I retrieve an array of boolean values using Parse Cloud Code. I'm new to C# so I assume that the array gets assigned to result. But how can I access the individual elements of the array?

Right now I just get System.Collections.Generic.List1[System.Object]

Thomas Weller
  • 55,411
  • 20
  • 125
  • 222
nick9999
  • 601
  • 1
  • 8
  • 22
  • Not familiar with the library you are calling so I don't know the types, but you can use the foreach construct like this: foreach (FooShiftCount element in result) { element.CallSomeMethod(); } – Cortright May 26 '15 at 20:03
  • Googling the question gives a 100% match at [MSDN](https://msdn.microsoft.com/en-us/library/aa288453%28v=vs.71%29.aspx) as the first result. See chapter "Accessing Array Members". Please do a minimum of research by yourself. – Thomas Weller May 26 '15 at 20:03
  • Based of the answer below, accessing it with results[2] does not work – nick9999 May 26 '15 at 20:05
  • If an answer solved your problem, then please do not modify the question to get your next problem fixed. Ask a new question instead. – Thomas Weller May 26 '15 at 20:05
  • My problem was not solved – nick9999 May 26 '15 at 20:05
  • @nick9999: you wanted to access an element of the array. The answer states how to do that: `var element = result[elementIndex];` – Thomas Weller May 26 '15 at 20:07
  • I think @Mati Cicero is suggesting you change your call so that instead of type you refer to >... did you do that before trying to access it with result[2] ? – Scott Prokopetz May 26 '15 at 20:07
  • @nick9999 Updated my answer to reflect your expected type. – Matias Cicero May 26 '15 at 20:08

1 Answers1

2

ParseCloud.CallFunctionAsync<T> is a generic method.

According to Parse Documentation, T is the type of data you will receive from your cloud function.

That is, if your getShiftCount returns a List<object>, then you should reformulate your function call to this:

var result = await ParseCloud.CallFunctionAsync<List<object>>("getShiftCount", test2);

Then, you would be able to obtain any individual element using an index:

int elementIndex = 2;
var element = result[elementIndex];
Matias Cicero
  • 25,439
  • 13
  • 82
  • 154
  • @nick9999 For the record, don't copy and paste my sample code, I don't know what exact type you expect from your cloud function. Instead, try to understand what the function does and try to fix it by your own. If that fails, I'm always here to help – Matias Cicero May 26 '15 at 20:05
  • "object" needs to be "Object" but other than that it worked. Thanks! – nick9999 May 26 '15 at 20:11