程序猿小小弟 2020-08-19 18:30 采纳率: 100%
浏览 80
已采纳

switch语句未经处理的异常?

萌新在学习写一个飞行棋
运行时switch那里会出现“未经处理的异常”
Maps是一个字段

```public static int[] Maps = new int[100];
public static string Condition(int i) //声明一个i,给方法里使用
{
string str = " ";
if ((Player[0] == Player[1]) && Player[1] == i)//如果玩家A和玩家B在一起时
{
str = "<>";
}
else if (Player[0] == i)//玩家A
{
str = "A";
}
else if (Player[1] == i)//玩家B
{
str = "B";
}
else
{
switch (Maps[i])
{
case 0://调用上面的用来定义道具得是数字,数组里未经改变的值都是0
Console.ForegroundColor = ConsoleColor.White;
str = "□";//普通格子
break;
case 1:
Console.ForegroundColor = ConsoleColor.Green;
str = "☆";//幸运星
break;
case 2:
Console.ForegroundColor = ConsoleColor.Red;
str = "?";//地雷
break;
case 3:
Console.ForegroundColor = ConsoleColor.Blue;
str = "■";//暂停
break;
case 4:
Console.ForegroundColor = ConsoleColor.Yellow;
str = "卍";//时空隧道
break;
}
}
return str;

}

  • 写回答

1条回答 默认 最新

  • threenewbee 2020-08-19 18:59
    关注

    调用的代码呢,switch (Maps[i]),这里i传入多少,是否越界

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类