Monotouch how to retrieve objectAtIndex from NSArray in C#

c#, nsarray

Solution

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);

Problem

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.

Original source