Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Monotouch how to retrieve objectAtIndex from NSArray in C#

Tags:

c#

nsarray

In objectiveC given an NSArray fred containing strings I can say:

NSString *s = [fred ObjectAtIndex:5];

What is the c# equivalent? Rosetta stone says to use the method ValueAt but that returns an IntPtr.

var i = fred.ValueAt(5);

But then you are left with how to convert an IntPtr to NSString pointer.

like image 227
Bill McDuff Avatar asked Dec 15 '22 23:12

Bill McDuff


1 Answers

Going via IntPtr feels like a bad idea. Instead, as long as you know the type of the item you want to get, you can just use the following:

int index = 0;
NSString str = myNsArr.GetItem<NSString>(index);
like image 169
user3533716 Avatar answered Dec 28 '22 09:12

user3533716