System.IndexOutOfRangeException:索引已超出界限 [英] System.IndexOutOfRangeException: Index was out of bounds
问题描述
我在C#,当我在Visual Studio中运行它正常工作程序。
I have a program in C# that works fine when I run it in Visual Studio.
但是当我运行该文件,我得到的主要错误。
But when I run the file I get an error in main.
该错误是:
的未处理的异常:System.IndexOutOfRangeException:索引超出了数组的边界的
我公司主营:
的错误是在的 INT塔拉= convert.toInt32 ... 的
namespace MultiplicationTable
{
class Program
{
static void Main(string[] args)
{
int tala = Convert.ToInt32(args[0]);
MultiplicationTable test = new MultiplicationTable(tala);
Console.ReadLine();
}
}
}
任何想法?
Any ideas?
推荐答案
问题::当您从Visual Studio您提供的论点,但运行它时,你直接运行程序通过双击它,你不能提供,因为将非常具有直接调用的参数
Problem : When you run it from Visual Studio you are providing the arguments but when you run the program directly by double clicking on it you can not provide the arguments as it willbe invoked directly.
解决方案:您需要正确提供命令行参数,按照下面的步骤来运行命令行程序
Solution : you need to provide command line arguments properly, follow the below steps to run your program from command line
第1步:转到命令提示符
第二步:转到您的程序exe文件的路径
Step 2: goto your program exe file path
第3步:现在执行程序提供如下命令行参数:
Step 3: now execute the program by providing commandline arguments as below:
c:\myprogrampath\program.exe 12
试试这个代码,以避免例外:
Try This code to avoid Exceptions:
if(args.Length>0)
{
int tala = Convert.ToInt32(args[0]);
MultiplicationTable test = new MultiplicationTable(tala);
Console.ReadLine();
}
else
{
Console.WriteLine("No Command Line Arguments - Quiting");
}
这篇关于System.IndexOutOfRangeException:索引已超出界限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!