次の方法で共有


PreferencesStore.GetValue メソッド

定義

ユーザー設定ストアから、指定した名前と値のペアの値部分を取得します。

オーバーロード

GetValue(String, Boolean)

指定した既定のブール値を使用して、ユーザー設定ストアから指定した名前と値のペアの値部分を取得します。

GetValue(String, Int32)

指定した既定の整数値を使用して、ユーザー設定ストアから指定した名前と値のペアの値部分を取得します。

GetValue(String, String)

指定した既定の文字列値を使用して、ユーザー設定ストアから指定した名前と値のペアの値部分を取得します。

GetValue(String, Boolean)

指定した既定のブール値を使用して、ユーザー設定ストアから指定した名前と値のペアの値部分を取得します。

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

パラメーター

name
String

基本設定ストア項目の名前。

defaultValue
Boolean

名前付き基本設定ストア項目が見つからない場合に返す値。

戻り値

名前付き基本設定ストア 項目の値 (見つかった場合)。それ以外の場合は、 パラメーターの defaultValue 値。

例外

namenull または空です。

次の例では、名前付き基本設定ストア項目の値をトレース リスナーに書き込みます。

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 + "\"");

}

適用対象

GetValue(String, Int32)

指定した既定の整数値を使用して、ユーザー設定ストアから指定した名前と値のペアの値部分を取得します。

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

パラメーター

name
String

基本設定ストア項目の名前。

defaultValue
Int32

名前付き基本設定ストア項目が見つからない場合に返す値。

戻り値

名前付き基本設定ストア 項目の値 (見つかった場合)。それ以外の場合は、 パラメーターの defaultValue 値。

例外

namenull または空です。

次の例では、名前付き基本設定ストア項目の値をトレース リスナーに書き込みます。

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());

}

適用対象

GetValue(String, String)

指定した既定の文字列値を使用して、ユーザー設定ストアから指定した名前と値のペアの値部分を取得します。

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

パラメーター

name
String

基本設定ストア項目の名前。

defaultValue
String

名前付き基本設定ストア項目が見つからない場合に返す値。

戻り値

名前付き基本設定ストア 項目の値 (見つかった場合)。それ以外の場合は、 パラメーターの defaultValue 値。

例外

namenull または空です。

次の例では、 "This name is not in the store" Value = "My Default Val" トレース リスナーに書き込みます。

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 + "\"");

次の例では、名前付き基本設定ストア項目の値をトレース リスナーに書き込みます。

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 + "\"");

}

適用対象