Quick Tip: C# Linq dot Any

23 June 2009
 

How many times have you written code like this:

if(person.Addresses.Count > 0)
 {
 //Then do something here...
 }

I’m sure the answer is “lots”, and I’m still writing code like this. Well the trick is that Linq has lots of extension methods that you may have missed/not used/don’t know what it does etc. One of these methods is the “Any” method. Now I can write the previous code as:

if(person.Addresses.Any())
 {
 //Then do something here...
 }

I need to remember that this one is there!

Search

Categories

Archives

Subscribe to Email Updates

Subscribe
 

Comments are closed.

We are a digital transformation consultancy. We help our clients succeed.

View Services