且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何检查IEnumerable是null还是空?

更新时间:2023-11-29 16:09:16

b
$ b

Sure you could write that:

public static class Utils {
    public static bool IsAny<T>(this IEnumerable<T> data) {
        return data != null && data.Any();
    }
}

但是,注意并非所有序列都是可重复的; 我更喜欢只走一次,以防万一。

however, be cautious that not all sequences are repeatable; generally I prefer to only walk them once, just in case.