问题描述
美好的一天,我有一个清单< string>保存在我的应用程序用户设置中,此列表应该保存openfiledialog的文件路径然后反序列化它,但我已经调用方法Save();甚至方法Upgrade();将字符串添加到列表后,但此字符串不会保存。为什么?
我尝试过:
保存它:
private void ImportIcon_Click(object sender,EventArgs e)
{
IfSound();
openFileDialog1.Filter =Analytica Files(* .analy)| * .analy;
openFileDialog1.Multiselect = true;
if(openFileDialog1.ShowDialog()== DialogResult.OK)
{
var Path = openFileDialog1.FileName;
foreach(openFileDialog1.FileNames中的字符串文件)
{
Settings.Default.FileList.Add(file);
Settings.Default.Save();
//Settings.Default.Upgrade ();
}
Good Day, I Have A List<string> Saved In My App User Settings, this List is supposed to save the file paths of a openfiledialog to then deserialize it, but I already Called the method Save(); And even the method Upgrade(); After adding the strings to the list, but this strings doesn´t save. Why?
What I have tried:
To Save It:
private void ImportIcon_Click(object sender, EventArgs e)
{
IfSound();
openFileDialog1.Filter = "Analytica Files (*.analy) |*.analy";
openFileDialog1.Multiselect = true;
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
var Path = openFileDialog1.FileName;
foreach (string file in openFileDialog1.FileNames)
{
Settings.Default.FileList.Add(file);
Settings.Default.Save();
//Settings.Default.Upgrade();
}
推荐答案
if(Properties.Settings.Default.TestList == null)
{
MessageBox.Show("Not initialised");
// Create a new List and Save to Settings
Properties.Settings.Default.TestList = new System.Collections.Specialized.StringCollection();
Properties.Settings.Default.Save();
}
else if(Properties.Settings.Default.TestList.Count > 0)
{
// Create a message showing the last value in the list and the count of items
string strMsg = string.Format("List is populated\r\nLast Value: {0}\r\nCount: {1}", Properties.Settings.Default.TestList[Properties.Settings.Default.TestList.Count - 1].ToString(), Properties.Settings.Default.TestList.Count.ToString());
MessageBox.Show(strMsg);
}
else
{
MessageBox.Show("Currently empty");
}
string[] myTest = new string[] { "Value 1", "Value 2" };
foreach(string myVal in myTest)
{
Properties.Settings.Default.TestList.Add(myVal);
}
Properties.Settings.Default.Save();
if (Properties.Settings.Default.TestList.Count > 0)
{
MessageBox.Show("After populate\r\n" + Properties.Settings.Default.TestList[0].ToString()
+ "\r\nCount: " + Properties.Settings.Default.TestList.Count);
}
亲切的问候
Kind Regards
这篇关于为什么我的列表< string>不救?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!