Compartilhar via


PreferencesStore.SetValue Método

Definição

Remove, adiciona ou substitui um item no repositório de preferências.

Sobrecargas

SetValue(String, Boolean, Boolean)

Remove, adiciona ou substitui um item no repositório de preferências, usando os valores boolianos especificados.

SetValue(String, Int32, Int32)

Remove, adiciona ou substitui um item no repositório de preferências, usando os valores inteiros especificados.

SetValue(String, String, String)

Remove, adiciona ou substitui um item no repositório de preferências, usando os valores de cadeia de caracteres especificados.

SetValue(String, Boolean, Boolean)

Remove, adiciona ou substitui um item no repositório de preferências, usando os valores boolianos especificados.

public:
 void SetValue(System::String ^ name, bool value, bool defaultValue);
public void SetValue (string name, bool value, bool defaultValue);
member this.SetValue : string * bool * bool -> unit
Public Sub SetValue (name As String, value As Boolean, defaultValue As Boolean)

Parâmetros

name
String

O nome do item da loja.

value
Boolean

O valor a ser definido para o item de repositório nomeado.

defaultValue
Boolean

O indicador de valor de redefinição.

Exceções

name é null ou vazio.

Exemplos

O exemplo a seguir salva um bool item no repositório, altera o valor e exclui o item.

void TrcBoolVal(string name) {

    PreferencesStore store = MyPrefStore;

    bool b = store.ContainsValue(name);
    Trace.WriteLine("ContainsValue(\"" + name + "\") : "
        + b.ToString());

    if (b == false)
        return;

    bool myCnfgBoolVal = store.GetValue(name, false);
    Trace.WriteLine(name + " Value: "
    + myCnfgBoolVal.ToString());

}
void TrcSetBool() {

    PreferencesStore store = MyPrefStore;

    string name = "MyBool";

    store.SetValue(name, true, false);
    TrcBoolVal(name);

    store.SetValue(name, false, true);
    TrcBoolVal(name);

    store.SetValue(name, true, true);
    TrcBoolVal(name);
}

Comentários

Se os value parâmetros e defaultValue forem iguais, o item será removido do repositório.

Aplica-se a

SetValue(String, Int32, Int32)

Remove, adiciona ou substitui um item no repositório de preferências, usando os valores inteiros especificados.

public:
 void SetValue(System::String ^ name, int value, int defaultValue);
public void SetValue (string name, int value, int defaultValue);
member this.SetValue : string * int * int -> unit
Public Sub SetValue (name As String, value As Integer, defaultValue As Integer)

Parâmetros

name
String

O nome do item da loja.

value
Int32

O valor a ser definido para o item de repositório nomeado.

defaultValue
Int32

O indicador de valor de redefinição.

Exceções

name é null ou vazio.

Exemplos

O exemplo a seguir salva um int item no repositório, altera o valor e exclui o item.

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

}
void TrcSetInt() {

    PreferencesStore store = MyPrefStore;
    string name = "MyInt";

    store.SetValue(name, 12, 321);
    TrcVal(name, 45678);

    store.SetValue(name, 321, 12);
    TrcVal(name, 45678);

    store.SetValue(name, 12, 12);
    TrcVal(name, 45678);
}

Comentários

Se os value parâmetros e defaultValue forem os mesmos, esse método removerá o item do repositório.

Aplica-se a

SetValue(String, String, String)

Remove, adiciona ou substitui um item no repositório de preferências, usando os valores de cadeia de caracteres especificados.

public:
 void SetValue(System::String ^ name, System::String ^ value, System::String ^ defaultValue);
public void SetValue (string name, string value, string defaultValue);
member this.SetValue : string * string * string -> unit
Public Sub SetValue (name As String, value As String, defaultValue As String)

Parâmetros

name
String

O nome do item da loja.

value
String

O valor a ser definido para o item de repositório nomeado.

defaultValue
String

O indicador de valor de redefinição.

Exceções

O name parâmetro ou value está null ou vazio.

Exemplos

O exemplo a seguir salva um item de cadeia de caracteres no repositório, altera o valor e exclui o item.

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

}
void TrcSetStrng() {

    PreferencesStore store = MyPrefStore;
    string name = "MyString";
    string sA = "abc";
    string sX = "X-12345";
    string sDefault = "My Default String";

    store.SetValue(name, sA, sX);
    TrcVal(name, sDefault);

    store.SetValue(name, sX, sA);
    TrcVal(name, sDefault);

    store.SetValue(name, sA, sA);
    TrcVal(name, sDefault);
}

Comentários

Se os value parâmetros e defaultValue forem iguais, o item será removido do repositório.

Aplica-se a