# DevicePreferences

Namespace: **Wisej.Hybrid**

Assembly: **Wisej.Hybrid** (3.5.0.0)

Manages device preferences, allowing retrieval and storage of user preferences.

{% tabs %}
{% tab title="C#" %}

```csharp
public class DevicePreferences
```

{% endtab %}

{% tab title="VB.NET" %}

```visual-basic
Public Class DevicePreferences
```

{% endtab %}
{% endtabs %}

Access this class through the [Device](https://docs.wisej.com/hybrid/start/api/general/wisej.hybrid.device) singleton.

## Constructors

### ![](https://1168517704-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FKLgWHTlbcMvpwVT7mLBW%2Fuploads%2Fgit-blob-2389c55cd19719a73a5ae98e1528c8dc8525cc35%2Finstance.png?alt=media)DevicePreferences()

Initializes a new instance of [DevicePreferences](https://docs.wisej.com/hybrid/start/api/storage/wisej.hybrid.devicepreferences).

## Methods

### ![](https://1168517704-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FKLgWHTlbcMvpwVT7mLBW%2Fuploads%2Fgit-blob-2389c55cd19719a73a5ae98e1528c8dc8525cc35%2Finstance.png?alt=media)Clear(sharedName)

Clears all preferences.

| Parameter                                                                                                                                                                                                                    | Type                                                          | Description                                      |
| ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------- | ------------------------------------------------ |
| **sharedName** ![](https://1168517704-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FKLgWHTlbcMvpwVT7mLBW%2Fuploads%2Fgit-blob-723b640963c6cd781ff8c5ce5b24149fa0af7b9c%2Fbadge-optional.svg?alt=media) | [String](https://docs.microsoft.com/dotnet/api/system.string) | An optional name for a shared preferences space. |

### ![](https://1168517704-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FKLgWHTlbcMvpwVT7mLBW%2Fuploads%2Fgit-blob-2389c55cd19719a73a5ae98e1528c8dc8525cc35%2Finstance.png?alt=media)ContainsKey(key, sharedName)

Checks if the preferences contain a given key.

| Parameter                                                                                                                                                                                                                    | Type                                                          | Description                                      |
| ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------- | ------------------------------------------------ |
| **key**                                                                                                                                                                                                                      | [String](https://docs.microsoft.com/dotnet/api/system.string) | The key to check within the preferences.         |
| **sharedName** ![](https://1168517704-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FKLgWHTlbcMvpwVT7mLBW%2Fuploads%2Fgit-blob-723b640963c6cd781ff8c5ce5b24149fa0af7b9c%2Fbadge-optional.svg?alt=media) | [String](https://docs.microsoft.com/dotnet/api/system.string) | An optional name for a shared preferences space. |

**Returns:** [Boolean](https://docs.microsoft.com/dotnet/api/system.boolean). true if the preference contains the key; otherwise, false.

### ![](https://1168517704-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FKLgWHTlbcMvpwVT7mLBW%2Fuploads%2Fgit-blob-2389c55cd19719a73a5ae98e1528c8dc8525cc35%2Finstance.png?alt=media)Get(key, defaultValue, sharedName)

Retrieves the value of a preference specified by the key.

| Parameter                                                                                                                                                                                                                    | Type                                                          | Description                                                   |
| ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------- | ------------------------------------------------------------- |
| **key**                                                                                                                                                                                                                      | [String](https://docs.microsoft.com/dotnet/api/system.string) | The key for the desired preference.                           |
| **defaultValue**                                                                                                                                                                                                             | [Object](https://docs.microsoft.com/dotnet/api/system.object) | The default value to return if the preference does not exist. |
| **sharedName** ![](https://1168517704-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FKLgWHTlbcMvpwVT7mLBW%2Fuploads%2Fgit-blob-723b640963c6cd781ff8c5ce5b24149fa0af7b9c%2Fbadge-optional.svg?alt=media) | [String](https://docs.microsoft.com/dotnet/api/system.string) | An optional name for a shared preferences space.              |

**Returns:** [Object](https://docs.microsoft.com/dotnet/api/system.object). The value of the preference if it exists; otherwise, the default value.

### ![](https://1168517704-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FKLgWHTlbcMvpwVT7mLBW%2Fuploads%2Fgit-blob-2389c55cd19719a73a5ae98e1528c8dc8525cc35%2Finstance.png?alt=media)Remove(key, sharedName)

Removes a preference specified by the key.

| Parameter                                                                                                                                                                                                                    | Type                                                          | Description                                      |
| ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------- | ------------------------------------------------ |
| **key**                                                                                                                                                                                                                      | [String](https://docs.microsoft.com/dotnet/api/system.string) | The key for the preference to remove.            |
| **sharedName** ![](https://1168517704-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FKLgWHTlbcMvpwVT7mLBW%2Fuploads%2Fgit-blob-723b640963c6cd781ff8c5ce5b24149fa0af7b9c%2Fbadge-optional.svg?alt=media) | [String](https://docs.microsoft.com/dotnet/api/system.string) | An optional name for a shared preferences space. |

### ![](https://1168517704-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FKLgWHTlbcMvpwVT7mLBW%2Fuploads%2Fgit-blob-2389c55cd19719a73a5ae98e1528c8dc8525cc35%2Finstance.png?alt=media)Set(key, value, sharedName)

Sets the value of a boolean preference specified by the key.

| Parameter                                                                                                                                                                                                                    | Type                                                            | Description                                      |
| ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------- | ------------------------------------------------ |
| **key**                                                                                                                                                                                                                      | [String](https://docs.microsoft.com/dotnet/api/system.string)   | The key for the desired preference.              |
| **value**                                                                                                                                                                                                                    | [Boolean](https://docs.microsoft.com/dotnet/api/system.boolean) | The value to set for the preference.             |
| **sharedName** ![](https://1168517704-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FKLgWHTlbcMvpwVT7mLBW%2Fuploads%2Fgit-blob-723b640963c6cd781ff8c5ce5b24149fa0af7b9c%2Fbadge-optional.svg?alt=media) | [String](https://docs.microsoft.com/dotnet/api/system.string)   | An optional name for a shared preferences space. |

### ![](https://1168517704-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FKLgWHTlbcMvpwVT7mLBW%2Fuploads%2Fgit-blob-2389c55cd19719a73a5ae98e1528c8dc8525cc35%2Finstance.png?alt=media)Set(key, value, sharedName)

Sets the value of a string preference specified by the key.

| Parameter                                                                                                                                                                                                                    | Type                                                          | Description                                      |
| ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------- | ------------------------------------------------ |
| **key**                                                                                                                                                                                                                      | [String](https://docs.microsoft.com/dotnet/api/system.string) | The key for the desired preference.              |
| **value**                                                                                                                                                                                                                    | [String](https://docs.microsoft.com/dotnet/api/system.string) | The value to set for the preference.             |
| **sharedName** ![](https://1168517704-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FKLgWHTlbcMvpwVT7mLBW%2Fuploads%2Fgit-blob-723b640963c6cd781ff8c5ce5b24149fa0af7b9c%2Fbadge-optional.svg?alt=media) | [String](https://docs.microsoft.com/dotnet/api/system.string) | An optional name for a shared preferences space. |
