The most common use for Preprocessor Directives is to intelligently group your code using the #region … #endregion tag (sidenote: Ctrl + M, M is a great keyboard shortcut to expand and contract your regions). Preprocessor Directives can also be used to tell the compiler which code should or should not be compiled based on the configuration environment. Wrapping code in an #if DEBUG … #endif block will only execute if the environment is in debug mode. This proved to be a handy way to debug a situation ......
On Jan 16, 2011, we are expecting a new addition to our family. Ben is going to learn words like “share” and “don’t put that in the baby’s nose”. We expect he’ll do great ......
There is a sales technique where the strategy is to get the customer to say “No deal” as soon as possible. The idea being that by establishing terms that your customer is not comfortable with with, the sooner you can figure out what they will be willing to agree to. The same principal can be applied to code design. Instead of nested if…then statements, a code block should quickly eliminate the cases it is not equipped to handle and just focus on what it is meant to handle. This is code that will ......
A lot of reports work on data from last month. It is a nice touch to have these dates pre-populated for your users. Using extension methods, the code can look cleaner too. Extension Methods: public static class DateHelper { public static DateTime FirstOfTheMonth(this DateTime dt) { return new DateTime(dt.Year, dt.Month, 1); } public static DateTime LastOfTheMonth(this DateTime dt) { return dt.FirstOfTheMonth().AddMon... } } Consuming Code: void Prepopulate() { startDateBox.CurrentlySelec... ......
I would like to blog more about the problems I encounter on a daily basis. I find that taking 10 minutes or so to write a simple solution to my problems helps me retain that information. I always forget the specific syntax to declaring variables in T-SQL. declare @startdate datetime; declare @enddate datetime; set @startdate = '04/01/2010'; set @enddate = '04/30/2010'; select count(id) from triphistory where tripdate between @startdate and @enddate ......