is this overkill for assessing Main(string[] args)

后端 未结 5 2005
無奈伤痛
無奈伤痛 2021-01-12 06:44

I\'ve got the following and was wondering if the initial test is overkill:

static void Main(string[] args) {
    if (args.Length == 0 || args == null) {              


        
5条回答
  •  猫巷女王i
    2021-01-12 07:07

    If there's no input data, then args.Length is equal to 0, but not null. If there's any input data, then agrs.Length is equal to count of input arguments. In conclusion, args can't be null, but length can be zero.

    PS check for null first always

提交回复
热议问题