错误的代码:
UpdateApplicationInfo[] uai = new UpdateApplicationInfo[3];
int position = 0;
foreach (DictionaryEntry de in ht)
{
uai[position].ApplicationGUID = de.Key.ToString();
uai[position].Version = de.Value.ToString();
position++;
}
正确的:
UpdateApplicationInfo[] uai = new UpdateApplicationInfo[3]; //只是分配了地址,但是没有指向正确的对象,因为还没有分配对象
for (int i = 0; i < 3; i++)
{
uai[i] = new UpdateApplicationInfo(); //注意分别初始化对象
}
int position = 0;
foreach (DictionaryEntry de in ht)
{
uai[position].ApplicationGUID = de.Key.ToString();
uai[position].Version = de.Value.ToString();
position++;
}