未处理 System.IndexOutOfRangeException

此用户昵称已被屏蔽 2011-10-17 06:32:44

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace gaibian
{
class Program
{
public static void Main()
{
//创建二维string类型数组
int[] mm = new int[2] { 3, 5 };
int[] nn = new int[2] { 2, 3 };
string[,] zz = (string[,]) Array.CreateInstance(typeof (string ),mm,nn );
for (int i=zz.GetLowerBound (0);i<=zz.GetUpperBound(0);i++)
{
for (int j=zz.GetLowerBound (0);j <=zz.GetUpperBound (1);j++)
{
int[] myIndicesArray = new int[2] {i,j};
zz.SetValue(Convert .ToString (i)+j,myIndicesArray );
}
}
//显示每一维的下限和上限
Console.WriteLine("维数是\t 下限是\t 上限是\t");
for (int i = 0; i < zz.Rank; i++)

Console.WriteLine("{0}\t{1}\t{2}",i,zz .GetLowerBound (i ),zz .GetUpperBound (i));
Console.WriteLine("\n 数组是:");
for (int i = zz.GetLowerBound(0); i <= zz.GetUpperBound(0); i++)
{
for (int j = zz.GetLowerBound(0); j <= zz.GetUpperBound(1); j++)
{
Console.Write("{0}", zz[i, j]);
}
Console.WriteLine();
}
Console.ReadKey();

}
}
}

...全文
89 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
呃 发现问题所在了 盗版书伤不起啊
  • 打赏
  • 举报
回复
zz.SetValue(Convert .ToString (i)+j,myIndicesArray ) 提示 索引超出了数组结限

1,978

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 其他语言讨论
社区管理员
  • 其他语言社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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