C# 怎么把一个数组赋值给一个二维数组,新手求解............................

hellenren12345 2012-10-11 03:19:05
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);
}
}

这样赋值不对,求正解。
...全文
860 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
hellenren12345 2012-10-11
  • 打赏
  • 举报
回复
小弟先谢过了,还没测试。不过6楼大哥应该是正解。
Hauk 2012-10-11
  • 打赏
  • 举报
回复
            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();
}
}


大概应该是这个样子的。。。
guosi198912 2012-10-11
  • 打赏
  • 举报
回复
楼主,你把问题说清楚一点,string pictures = "1|/|2|/|3";

这个是字符串吧,你是打算把这个字符串转换成string[][] 这个二维数组吗
hellenren12345 2012-10-11
  • 打赏
  • 举报
回复
他提示 dt.Columns[i]错误
hellenren12345 2012-10-11
  • 打赏
  • 举报
回复
不懂,小弟新手。求代码
读易的庄稼人 2012-10-11
  • 打赏
  • 举报
回复
先分割一次,再循环数组,再分割一次!
bdmh 2012-10-11
  • 打赏
  • 举报
回复
你这哪行, Split分割为一维数组,你还是循环赋值吧,或者用array的copy

110,538

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧