【发布时间】:2013-09-15 09:47:43
【问题描述】:
我正在尝试使用System.Collections.Specialized.StringCollection 保存默认设置。
我阅读了this post,根据它,即使在重新加载程序后,我也可以使用它并将我的设置保存在集合中,但目前我被卡住了。我无法从收藏中获取此设置。
这是我的代码:
StringCollection defValueArr = new StringCollection();//collection for saving def values
public bool SaveDefaultValueCollection(NumericUpDown numBox)
{
bool saved = false;
try
{
if (!saved)
{
string[] defArray = new string[1];
defArray[0] = numBox.Value.ToString();
defValueArr.AddRange(defArray);
return true;
}
else
{
return false;
}
}
catch (Exception ee)
{
MessageBox.Show(ee.Message);
return false;
}
}
及获取def设置的方法
public int GetDefaultVolume()
{
//here i'll got error
//invalid array item - out of range item
return Convert.ToInt32(defValueArr[0]);
}
我做错了什么?
【问题讨论】:
-
您需要添加一个资源文件..您不能只是实例化一个集合并希望最好..重新阅读您链接的问题。
-
所以我必须以任何方式将结果记录到文件中?并且我无法在集合中保存信息并在重新加载程序后获取它?
-
问问自己..这将如何工作(如果可能的话)?
标签: c# winforms collections