
Language essentials, gotchas
NOTE: With the introduction of two new interfaces in .NET 4.0, there is a cleaner way to implement the Publish Subscribe pattern in C# .NET. However, the ‘gotchas’ listed here still apply. Even with the new interfaces, one still needs … 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 – for a couple of … Continue reading
When tasked with generating Random numbers, some folks use a static method such as that shown below:
Code Snippet
static Random rn = new Random();
static int ReturnNextRandom(int maxIndex)
{
return rn.Next(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
Looping and Iterating is bad for performance right? So – a loop like the one below should be bad.
for (int i = 0; i <= iterations; i++)
{
foreach (int j in data)
{
… Continue reading
If you are trying to encapsulate a method that returns a value, Funcs are ideal. However, what if your method returns void? Func will not work (Funcs were designed to wrap methods with return values only). However, a similar construct, … Continue reading
Delegates are amongst the most powerful constructs in the C# language (Full Solution Download at the end of this article).
Some uses of delegates in c# include :
Delaying invocation(calling) of a method
Dynamically assigning target(s) to a method
Advanced eventing patterns using c# … Continue reading
Considering the amount of time they have saved mankind, Hash-functions are among the most under-appreciated gems of computing. A hashing function will typically, using just a SINGLE lookup – retrieve a deeply buried patient record or a stock quote or … Continue reading