CodeKicks.com
Focus on Microsoft Technologies - Tutorials, Articles, Code Samples.

Tuesday, August 29, 2006

Predicates in C#

This code sample applies to ASP.NET in the .NET 2.0 framework. Examples are written in C#.

Contents

  1. Overview
  2. So What are Predicates?
  3. How do I Use Them?
  4. Performance
  5. As Long as We're Here: Actions and Converters
  6. Conclusion

Overview:

Like mathematicians, developers talk about their code in aesthetic and sometimes hygienic terms. The code is “elegant,” or it “looks clean,” and sometimes it “smells bad”. I have even heard developers refer to their code as “sexy.” Talking about your code as sexy is surely a sign that you need to get out more! Achieving elegant code is not easy and so as I deepen my experience with .Net 2.0, I am always pleased to discover when the framework offers a way to do something that I could have done in 1.1, but can now do much more elegantly. Predicates and the related Actions and Converters are just such additions to the framework. They will not revolutionise how you code, but used properly they will reduce the amount of code needed, encourage reuse, and just look sexier.

This article will examine the following questions:

  • What are Predicates?
  • How they are used?
  • How does their performance stack up against similar foreach routines?
  • What are Actions and Converters?

Continue Predicates in C#…

, , , ,

Post a Comment