C#检查你是否传递了参数

前端之家收集整理的这篇文章主要介绍了C#检查你是否传递了参数前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有这个代码
  1. public static void Main(string[] args)
  2. {
  3. if (string.IsNullOrEmpty(args[0])) // Warning : Index was out of the bounds of the array
  4. {
  5. ComputeNoParam cptern = new ComputeNoParam();
  6. cptern.ComputeWithoutParameters();
  7. }
  8. else
  9. {
  10. ComputeParam cpter = new ComputeParam();
  11. foreach (string s in args){...}
  12. }
  13. }

也试过if(args.Length == 0),但它仍然不起作用.

基本上我想知道用户是否用参数调用程序.如果程序没有要求输入.

我该怎么做?@H_403_9@提前致谢.

解决方法

if(args.Length == 0)应该工作,args [0]需要至少一个参数不会崩溃.

猜你在找的C#相关文章