IsNullOrEmpty equivalent for Array? C#

后端 未结 11 1429
轻奢々
轻奢々 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条回答
  •  -上瘾入骨i
    2020-12-08 19:29

    This is an updated C# 8 version of the (currently) up-voted answer

    public static bool IsNullOrEmpty([NotNullWhen(false)] this T[]? array) =>
        array == null || array.Length == 0;
    

提交回复
热议问题