45 subscribers








C# – the language
  |  Technology  |  Science Stuff  |  Travel  |  Entertainment  |  Buddhism  |  Finance and Investing  |  Austin  |  India  |  Diet, Health  |  Petitions, Causes  |  

Language essentials, gotchas

The Publish Subscribe Pattern in C# and some gotchas | Posted on by Anuj Varma

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


C#, .NET Exception Handling Best Practices | Posted on by Anuj Varma

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


New interfaces for implementing Publish-Subscribe in .NET | Posted on by Anuj Varma

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


Generating Random Numbers C# | Posted on by Anuj Varma

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


Swapping without a temp variable | Posted on by Anuj Varma

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


LINQ versus looping–Performance | Posted on by Anuj Varma

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


Use Funcs only if you want results back | Posted on by Anuj Varma

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 in C# – pre-lambda and post-lambda expressions | Posted on by Anuj Varma

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