c# - How to check if IEnumerable is null or empty? -
i love string.isnullorempty
method. i'd love have allow same functionality ienumerable. there such? maybe collection helper class? reason asking in if
statements code looks cluttered if patter (mylist != null && mylist.any())
. cleaner have foo.isany(mylist)
.
this post doesn't give answer: ienumerable empty?.
sure could write that:
public static class utils { public static bool isany<t>(this ienumerable<t> data) { return data != null && data.any(); } }
however, cautious not sequences repeatable; generally prefer walk them once, in case.
Comments
Post a Comment