testing
testing

Reputation: 20289

Get float value out from NSDictionary

I'm seeking for a solution in C#. I have a dictionary like

NSDictionary metrics = new NSDictionary ("leftInset", 22);

Now I want to get the number as float. I tried this

metrics.ValueForKey(new NSString("leftInset"))

but the return value is of type NSObject. How can I get the float?

Upvotes: 3

Views: 3724

Answers (2)

poupou
poupou

Reputation: 43553

float f = (metrics ["leftInset"] as NSNumber).FloatValue;

Upvotes: 5

Glenn Wilson
Glenn Wilson

Reputation: 241

Cast it to an NSNumber.

NSDictionary:

There is a convenient constructor that takes at least one key and one value, with optional values that will create the dictionary by pairing each key with a value. If you use .NET objects, the keys and values will first be boxed into NSObjects using NSObject.FromObject.

Upvotes: 3

Related Questions