Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用存储在.settings中的数组时,无法初始化或设置值_C#_Arrays_Visual Studio 2012_Settings - Fatal编程技术网

C# 使用存储在.settings中的数组时,无法初始化或设置值

C# 使用存储在.settings中的数组时,无法初始化或设置值,c#,arrays,visual-studio-2012,settings,C#,Arrays,Visual Studio 2012,Settings,我正在尝试在程序的设置中存储数组。关于如何在设置中创建System.Int32数组,我引用了另一个stackoverflow问题,但现在我在实际使用数组本身时遇到了问题 我想设置数组大小int[100],然后像其他设置一样从中设置/检索值。无论何时尝试以任何方式访问或以其他方式操作该属性,我都不会将对象引用设置为对象错误的实例,因为该值为null。我试图使它不为空,但我不能,因为它已经为空了,有人能帮忙吗 该数组称为InBateCellPreference **更新时,我还意识到设计器中的设置范

我正在尝试在程序的设置中存储数组。关于如何在设置中创建System.Int32数组,我引用了另一个stackoverflow问题,但现在我在实际使用数组本身时遇到了问题

我想设置数组大小int[100],然后像其他设置一样从中设置/检索值。无论何时尝试以任何方式访问或以其他方式操作该属性,我都不会将对象引用设置为对象错误的实例,因为该值为null。我试图使它不为空,但我不能,因为它已经为空了,有人能帮忙吗

该数组称为InBateCellPreference


**更新时,我还意识到设计器中的设置范围设置为APPLICATION而不是USER。一旦我将其更改为用户,我就能够绕过只读问题**

哪一行出错?这意味着您的设置没有实际实例化,如果是您的值设置,您将得到索引错误。。。您将获得null ref。进入调试并验证此设置变量是否实际存在。这意味着它为null请在循环之前尝试此操作:Optimo_Formation_Scheduler_C_sharp.Properties.Settings.Default.InbateCellPreference=new Int32[dgvPrefList.Rows.Count];在我让你添加的线上?
int preferlistcounter = 0;
Int32[] preferlist = new Int32[dgvPrefList.Rows.Count];
for (int i = 0; i < dgvPrefList.Rows.Count; i++)
{
    //initialize the array
    Properties.Settings.Default.InbatecCellPreference.SetValue(0, i);

    if ((bool)dgvPrefList[0, i].Value == true)
    {
        preferlist[preferlistcounter] = Convert.ToInt16(dgvPrefList["CellID", i]);
        //set the array to the value of preferlist
        Properties.Settings.Default.InbatecCellPreference.SetValue(preferlist[preferlistcounter], preferlistcounter);
        preferlistcounter++;
    }
}
//save changes after the loop has completed
Properties.Settings.Default.Save();