Shawn Weisfeld

I find when I talk to myself nobody listens. - Shawn Weisfeld
posts - 350, comments - 129, trackbacks - 34

My Links

News

The views expressed in this blog are mine and mine alone, not that of my employer, Microsoft, or anyone else’s. No warrantee is given for the quality of any material on this site.

Archives

Post Categories

LINQ Between

 

Last night at the Dallas .NET UG (http://www.ddnug.net/) Corey Smith (http://addressof.com) demoed a between extension method in VB.NET. I threw together this version for C# for your enjoyment Smile

image

 

All it is doing is wrapping the built in Where LINQ method . . .

As you can see that it will work on any type that implements IComparable (http://msdn.microsoft.com/en-us/library/system.icomparable.aspx). IComparable is used in .NET for ordering and sorting, just what we need!

 

Here is how you would call him:

image

As you can see there is an optional parameter at the end, so you can select if you want an inclusive or exclusive between (i.e. inclusive says we should return 10 & 20 in the results and exclusive says we should not). I defaulted it to true since that is the behavior of SQL Server (http://msdn.microsoft.com/en-us/library/ms187922.aspx)

Happy coding!

Print | posted on Friday, July 22, 2011 9:25 AM |

Feedback

No comments posted yet.

Post Comment

Title  
Name  
Email
Url
Comment   
Please add 7 and 7 and type the answer here:

Powered by: