我有这个代码:
- public static void Main(string[] args)
- {
- if (string.IsNullOrEmpty(args[0])) // Warning : Index was out of the bounds of the array
- {
- ComputeNoParam cptern = new ComputeNoParam();
- cptern.ComputeWithoutParameters();
- }
- else
- {
- ComputeParam cpter = new ComputeParam();
- foreach (string s in args){...}
- }
- }
也试过if(args.Length == 0),但它仍然不起作用.
基本上我想知道用户是否用参数调用程序.如果程序没有要求输入.
我该怎么做?@H_403_9@提前致谢.
解决方法
if(args.Length == 0)应该工作,args [0]需要至少一个参数不会崩溃.