Language essentials, gotchas
Delegates encapsulate a method. All they do is provide an alternate way to call (‘invoke’) a method. This concept has been around for a while (function pointers in C – and other languages). In C#, there are three things to … Continue reading
I was confused by the appearance of ‘params’ in the signature of a method (see example snippet below). It seemed redundant – even if I removed it, the method worked just fine.
void DisplayStrings(params string strings);
Params allows a short-cut during … Continue reading
Normally, when you invoke a method, it is invoked synchronously on your calling thread. Since you made no provision to ‘unblock’ the main thread, the method essentially ‘blocks’ the thread – which means that nothing else can happen until the … Continue reading
This post does three things:
Provides a complete implementation of the publish subscribe pattern in C#.
Highlights 4 potential issues that are inherent to ANY publish subscribe implementation – including the one provided here.
Provides original, tested workarounds … Continue reading
The Problem Statement
You have just started working on an existing codebase – an n-Tier project – and noticed that the Exception Handling framework wasn’t as well defined as you would expect. Some specific things that bother you include:
Lack of … Continue reading
You know you are a techie at heart if you find yourself getting excited at the introduction of a couple of new interfaces.
.NET 4.0 introduces IObservable (Publisher) and IObserver (Subscriber). These interfaces were long overdue – … Continue reading
When tasked with generating Random numbers, some folks use a static method such as that shown below:
static Random rn = new Random();
static int ReturnNextRandom(int maxIndex)
One of the reasons is that they want to keep the same, common instance … Continue reading
Everyone is familiar with the basic swap – using a temporary variable
static void RegularSwapUsingTempVariable(ref int a, ref int b)
int temp = a;
… Continue reading
Do you have an application that deals with currencies and/or monies of any sort? If you are not using the Decimal type (or more suitably, the Money special type included here), you are in for several conversion/rounding errors – which … Continue reading