navigation
 Saturday, January 26, 2008
Read how to implement the Singleton Design Pattern in C# using Generics
 | 
posted on January 26, 2008  #    by John Waters  Comments [0]
 Saturday, January 19, 2008
One of the things I have come to love about Linq is how you can focus more on declarative programming: focusing on what you want to accomplish rather than how...
posted on January 19, 2008  #    by John Waters  Comments [0]
 Monday, December 17, 2007
Three ways to access the query string as key-value pairs.
posted on December 17, 2007  #    by Adam Anderson  Comments [1]
 Sunday, December 16, 2007
Here is a new language feature that saves a lot of time and eliminates some mindless typing...
posted on December 16, 2007  #    by John Waters  Comments [0]
 Friday, December 14, 2007

I just learnt something new and cool from one of Scott Guthries blogs: the ?? null coalescing operator in C# 2.0. I never noticed it until now, and actually thought it was part of 3.0, until a kind reader corrected me... it's been around ever since the advent of nullable types in C#.

Basically, this operator works like the T-SQL ISNULL or COALESCE function. Read all about it in Scott's blog!

 

posted on December 14, 2007  #    by John Waters  Comments [0]
 Thursday, December 13, 2007

I recently installed the RTM version of Visual Studio 2008 (previously known as Orcas), which comes with C# 3.0 and .NET Framework 3.5. One of the coolest new things is LINQ, more on that in my next blog. The next coolest thing is the new C# 3.0 language support for lambda expressions, see the node  => part below:

 

XmlHelper.Visit(_rootTOCItem.ParentNode, "tocitem", 
  node => _tocItems.Add((XmlElement)node));

Where _tocItems is a List<XmlElement>  stored in the class that is calling this method.

This works because Visit accepts a delegate, and I am passing in an anonymous delegate above using the new syntax. Visit is just something I wrote that iterates over the nodes in an Xml tree. I could have used Link to Xml for that part, but this is a tree of XmlElements returned by an XmlDataProvider, and Linq to Xml operates on XElements.

 

public class XmlHelper
{
  public delegate void NodeVisitor(XmlNode node);
  
  public static void Visit( XmlNode node, string nodeNameFilter, NodeVisitor visitor )
  {
    if ( node.Name==nodeNameFilter)
      (node);
    if (node.HasChildNodes)
      foreach (XmlNode child in node.ChildNodes)
        (child, nodeNameFilter, visitor);
  }
}
posted on December 13, 2007  #    by John Waters  Comments [0]
 Tuesday, December 04, 2007
This technique is useful to show a page immediately upon request, then begin loading data after the page appears in the browser.
posted on December 4, 2007  #    by Adam Anderson  Comments [0]
 Friday, November 30, 2007
Read about how to alter a column in a replicated table without breaking replication.
posted on November 30, 2007  #    by John Waters  Comments [0]