Share via


PreferencesStore.GetValue Method

Definition

Gets the value portion of the specified name/value pair from the preference store.

Overloads

GetValue(String, Boolean)

Gets the value portion of the specified name/value pair from the preference store, using the specified default Boolean value.

GetValue(String, Int32)

Gets the value portion of the specified name/value pair from the preference store, using the specified default integer value.

GetValue(String, String)

Gets the value portion of the specified name/value pair from the preference store, using the specified default string value.

GetValue(String, Boolean)

Gets the value portion of the specified name/value pair from the preference store, using the specified default Boolean value.

public:
 bool GetValue(System::String ^ name, bool defaultValue);
public bool GetValue (string name, bool defaultValue);
member this.GetValue : string * bool -> bool
Public Function GetValue (name As String, defaultValue As Boolean) As Boolean

Parameters

name
String

The name of the preference store item.

defaultValue
Boolean

The value to return if the named preference store item is not found.

Returns

The value of the named preference store item, if found; otherwise, the value of the defaultValue parameter.

Exceptions

name is null or empty.

Examples

The following example writes the value of the named preference store item to the trace listener.

void TrcVal(string name, string strDefault) {

    PreferencesStore store = MyPrefStore;

    bool b = store.ContainsValue(name);
    if (b == false)
        Trace.WriteLine(name + " Not in store");

    string strVal = store.GetValue(name, strDefault);
    Trace.WriteLine(name + "Value = \""
        + strVal + "\"");

}

Applies to

GetValue(String, Int32)

Gets the value portion of the specified name/value pair from the preference store, using the specified default integer value.

public:
 int GetValue(System::String ^ name, int defaultValue);
public int GetValue (string name, int defaultValue);
member this.GetValue : string * int -> int
Public Function GetValue (name As String, defaultValue As Integer) As Integer

Parameters

name
String

The name of the preference store item.

defaultValue
Int32

The value to return if the named preference store item is not found.

Returns

The value of the named preference store item, if found; otherwise, the value of the defaultValue parameter.

Exceptions

name is null or empty.

Examples

The following example writes the value of the named preference store item to the trace listener.

void TrcVal(string name, int defVal) {

    PreferencesStore store = MyPrefStore;

    bool b = store.ContainsValue(name);
    if (b == false)
        Trace.WriteLine(name + " is not in store");


    int intVal = store.GetValue(name, defVal);
    Trace.WriteLine(name + " Value = "
        + intVal.ToString());

}

Applies to

GetValue(String, String)

Gets the value portion of the specified name/value pair from the preference store, using the specified default string value.

public:
 System::String ^ GetValue(System::String ^ name, System::String ^ defaultValue);
public string GetValue (string name, string defaultValue);
member this.GetValue : string * string -> string
Public Function GetValue (name As String, defaultValue As String) As String

Parameters

name
String

The name of the preference store item.

defaultValue
String

The value to return if the named preference store item is not found.

Returns

The value of the named preference store item, if found; otherwise, the value of the defaultValue parameter.

Exceptions

name is null or empty.

Examples

The following example writes "This name is not in the store" Value = "My Default Val" to the trace listener.

PreferencesStore store = MyPrefStore;
string name = "This name is not in the store";

bool b = store.ContainsValue(name);
if (b == true)
    throw new NotImplementedException(
        name + " was not expected to be found"
        );

string strVal = store.GetValue(name, "My Default Val");
Trace.WriteLine("\"" + name + "\"  Value = \""
    + strVal + "\"");

The following example writes the value of the named preference store item to the trace listener.

void TrcVal(string name, string strDefault) {

    PreferencesStore store = MyPrefStore;

    bool b = store.ContainsValue(name);
    if (b == false)
        Trace.WriteLine(name + " Not in store");

    string strVal = store.GetValue(name, strDefault);
    Trace.WriteLine(name + "Value = \""
        + strVal + "\"");

}

Applies to