C# 怎么把一个数组赋值给一个二维数组,新手求解............................
string[][] iPictures;
string pictures = "1|/|2|/|3";
DataSet ds = CoreLib.Crypt.XmlHelper.GetXml(xmlmodularPath);
DataTable dt = ds.Tables[0];
foreach (DataRow dr in dt.Rows)
{
//遍历列
for (int i = 0; i < dt.Columns.Count; i++)
{
///遍历添加到数组中
iPictures[dt.Columns[i]][i] = Regex.Split(dr[i].ToString(), "|/|", RegexOptions.IgnoreCase);
}
}
这样赋值不对,求正解。
------解决方案--------------------你这哪行, Split分割为一维数组,你还是循环赋值吧,或者用array的copy
------解决方案--------------------先分割一次,再循环数组,再分割一次!
------解决方案--------------------
C# code
string[,] iPictures;
string pictures = "1|/|2|/|3";
DataSet ds = CoreLib.Crypt.XmlHelper.GetXml(xmlmodularPath);
DataTable dt = ds.Tables[0];
iPictures = new string[dt.Rows.Count, dt.Columns.Count];
for (int j = 0; j < dt.Rows.Count; j++)
{
//遍历列
for (int i = 0; i < dt.Columns.Count; i++)
{
///遍历添加到数组中
iPictures[j][i] = dt.Rows[j][i].ToString();
}
}