Is if(items != null) superfluous before foreach(T item in items)?

后端 未结 12 1833
旧时难觅i
旧时难觅i 2020-12-07 14:28

I often come across code like the following:

if ( items != null)
{
   foreach(T item in items)
   {
        //...
   }
}

Basically, the

12条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-07 15:11

    As mentioned here you need to check is it not null.

    Do not use an expression that evaluates to null.

提交回复
热议问题