gpt4 book ai didi

windows-phone-7 - 更新隔离存储中的数据

转载 作者:行者123 更新时间:2023-12-01 12:55:23 25 4
gpt4 key购买 nike

我有一个代码可以在隔离空间中添加电子邮件 ID 和名称。但它无法添加多个数据。另外,如果输入的数据不正确,我该如何更新?

namespace IsoStore
{

public partial class MainPage : PhoneApplicationPage
{

// Constructor
public MainPage()
{
InitializeComponent();
IsolatedStorageSettings appSettings = IsolatedStorageSettings.ApplicationSettings;
}


private void button1_Click(object sender, RoutedEventArgs e)
{
IsolatedStorageSettings.ApplicationSettings.Add("email", "someone@somewhere.com");
IsolatedStorageSettings.ApplicationSettings.Add("name", "myname");
}

private void button2_Click(object sender, RoutedEventArgs e)
{
textBlock1.Text = (string)IsolatedStorageSettings.ApplicationSettings["email"];
textBlock2.Text = (string)IsolatedStorageSettings.ApplicationSettings["name"];
}
}
}

最佳答案

为您清理了一些代码,使用辅助方法来完成存储:

namespace IsoStore
{
public partial class MainPage : PhoneApplicationPage
{
private IsolatedStorageSettings _appSettings;

// Constructor
public MainPage()
{
InitializeComponent();
_appSettings = IsolatedStorageSettings.ApplicationSettings;
}


private void button1_Click(object sender, RoutedEventArgs e)
{
SaveSetting("email", "someone@somewhere.com");
SaveSetting("name", "myname");
}

private void button2_Click(object sender, RoutedEventArgs e)
{
textBlock1.Text = (string)_appSettings["email"];
textBlock2.Text = (string)_appSettings["name"];
}

private void SaveSetting( string setting, string value )
{
if (_appSettings.Contains(setting))
{
_appSettings[setting] = value;
}
else
{
_appSettings.Add(setting, value);
}
}
}
}

尝试一些其他示例来了解如何使用 IsolatedStorageSettings。

关于windows-phone-7 - 更新隔离存储中的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10004099/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com