IsNullOrEmpty equivalent for Array? C#

后端 未结 11 1438
轻奢々
轻奢々 2020-12-08 18:42

Is there a function in the .NET library that will return true or false as to whether an array is null or empty? (Similar to string.IsNullOrEmpty).

I had

11条回答
  •  遥遥无期
    2020-12-08 19:09

    Since C# 6.0, the null-propagation operator may be used to express concise like this:

    if (array?.Count.Equals(0) ?? true)
    

    Note 1: ?? false is necessary, because of the following reason

    Note 2: as a bonus, the statement is also "thread-safe"

提交回复
热议问题