我想将所有用户配置文件的多个字符串值存储到 Array 对象中。我的代码是:
if (upm != null)
{
for (int i = 0; i < otherMembers.Count; i++)
{
UserProfile user = upm.GetUserProfile(otherMembers[i]);
int j = 0;
if (user[FieldNames.OtherDepartment].Count != 0)
{
UserProfileValueCollection valueCollection = user[FieldNames.OtherDepartment];
Array otherDepartments = Array.CreateInstance(typeof(string), user[FieldNames.OtherDepartment].Count);
foreach (object value in valueCollection)
{
otherDepartments.SetValue(value.ToString(), j);
j++;
}
j = otherDepartments.Length;
otherDepartments.SetValue(fieldValue.Label, j);
user[FieldNames.OtherDepartment].Value = otherDepartments;
}
else
{
user[FieldNames.OtherDepartment].Value = fieldValue.Label;
}
//user[FieldNames.OtherDepartment].Value += fieldValue.Label;
user.Commit();
}
}
我在这条线上得到了错误:otherDepartments.SetValue(fieldValue.Label, j);
在forech()
循环之外。我错过了什么?