Tag: args

是评估Main(string args)的过度杀伤力

我有以下内容,并想知道初始测试是否过度杀伤: static void Main(string[] args) { if (args.Length == 0 || args == null) { //do X } else { //do Y } } 换句话说,我要问的是args.Length为零的可能性,或者args为null ….或者只是其中一个条件就足够了?

C#检查你是否通过了参数

我有这个代码: 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) ,但它仍然不起作用。 基本上我想知道用户是否使用参数调用程序。 如果不是,程序将要求输入。 我怎样才能做到这一点? 提前致谢。