Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 947
testing Avatar asked Sep 03 '26 01:09

testing


2 Answers

float f = (metrics ["leftInset"] as NSNumber).FloatValue;
like image 198
poupou Avatar answered Sep 04 '26 16:09

poupou


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.

like image 38
Glenn Wilson Avatar answered Sep 04 '26 14:09

Glenn Wilson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!