Thommy
Thommy

Reputation: 5407

Xamarin: How to implement NSDictionary with YES

I need to create a NSDictionary in Xamarin/C# with YES Value. The NSDictionary in Objective-C looks like this:

NSDictionary *requestSettings = @{
    kKeyOne : @YES,
    kKeyTwo : @YES
};

I have no idea where in Xamarin I can find the YES keyword.

Upvotes: 3

Views: 2754

Answers (3)

Nawnit
Nawnit

Reputation: 362

NSMutableDictionary dict = new NSMutableDictionary();

dict.Add("test", new NSNumber(true));

Upvotes: 9

miguel.de.icaza
miguel.de.icaza

Reputation: 32694

You can use CFBoolean.True and CFBoolean.False for your values.

Upvotes: 1

Santu C
Santu C

Reputation: 2654

To set values in Dictionary

Dictionary<string, bool> dictionary =
        new Dictionary<string, bool>();

dictionary.Add("kKeyOne", true);
dictionary.Add("kKeyTwo", true);

To get the value -

bool value = dictionary["kKeyOne"];

Upvotes: 2

Related Questions