Archive for June, 2009

How to get the parts of a URL in ASP.NET

Tuesday, June 30th, 2009

Every time I need to parse a URL or to extract parts of a URL in ASP.NET C# I can never remember what I did last time and need to refer to the documentation. So, in order to quickly answer the question "How can I get the elements of a ...

SELECT DISTINCT and ORDER BY

Wednesday, June 24th, 2009

ORDER BY items must appear in the select list if SELECT DISTINCT is specified. Recently discovered the above error (T-SQL, SQL Server) when trying to select DISTINCT rows for one set of columns while ordering the rows by another column. Jeff Smith had a good explanation of why this occurs (article). In ...

LINQ TO SQL : WHERE X IN ()

Monday, June 22nd, 2009

I recently needed to do a WHERE X IN () style query using LINQ to SQL. Here's the solution I used:

Extension methods (C#)

Monday, June 8th, 2009

Extension methods enable you to "add" methods to existing types without creating a new derived type, recompiling, or otherwise modifying the original type. Extension methods are a special kind of static method, but they are called as if they were instance methods on the extended type. For client code written ...

Delegates: Named methods, Anonymous methods, Lamda expressions (C#)

Monday, June 8th, 2009

Delegates The declaration of a delegate type is similar to a method signature. A delegate is a reference type that can be used to encapsulate a named or an anonymous method. Delegates are similar to function pointers in C++.

yield return (C#)

Monday, June 8th, 2009

The yield keyword signals to the compiler that the method in which it appears is an iterator block. The compiler generates a class to implement the behavior that is expressed in the iterator block. In the iterator block, the yield keyword is used together with the return keyword to provide ...