I'm not sure how I missed this one, but I have recently discovered the ?? operator in C# and I think that no day will pass again without me using it. Thanks to Mike who pointed it out to me.

So what does ?? do? It returns the object to its left if that object is not null, otherwise the object to its right. For example:

public IDataReader Search(DateTime? startDate, EndDate? endDate)
   IDbCommand cmd = provider.CreateCommand();
   cmd.CommandText = "dbo.SomeReportingProc";
   cmd.Connection = base.Context.Connection; // or whatever
   cmd.CommandType = CommandType.StoredProcedure;

   // StartDate
   cmd.Parameters.Add("@StartDate", startDate ?? DBNull.Value);
   cmd.Parameters.Add("@EndDate", endDate ?? DBNull.Value);

   return cmd.ExecuteReader();

And I thought it couldn't get better than the ternary operator.