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

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -