加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-15 06:29:05 所属栏目:百科 来源:网络整理
导读:我有这个代码: 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 { Com
我有这个代码:
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),但它仍然不起作用.

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

我该怎么做?
提前致谢.

解决方法

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读