LINQ–search for items in a list that are present in another list

Suppose you have a list of strings – a nursery rhyme may be a good example.  And you need to find ALL the words that match from another list of words.
Using LINQ to search a list for items in another list (should return a collection of all the matching words – “The,”, “Mouse”,”Up”

Using Delegates in C#

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 remember when using delegates. Just use the acronym D-A-I  for ‘Declare’, ‘Assign’ and ‘Invoke’.
Declaring […]

The ‘params’ keyword in c#

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 method invocation
While the method itself is unaffected by the ‘params’ in its signature, the caller […]

Async and Await, an easy way to keep your user interface responsive

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 method returns. What if your method was carrying out some time consuming task – such […]

The Publish Subscribe Pattern in C# and some gotchas

v\:* {behavior:url(#default#VML);}
o\:* {behavior:url(#default#VML);}
w\:* {behavior:url(#default#VML);}
.shape {behavior:url(#default#VML);}

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 for each of the 4 issues (source code included).

As far as the author is aware, […]

C#, .NET Exception Handling Best Practices

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 a Custom Exception Class
No clearly defined single layer (of the n-Tiers) which was designated to […]

New interfaces for implementing Publish-Subscribe in .NET

v\:* {behavior:url(#default#VML);}
o\:* {behavior:url(#default#VML);}
w\:* {behavior:url(#default#VML);}
.shape {behavior:url(#default#VML);}

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 reasons:

The ubiquitous nature of the Publish Subscribe pattern.
The cludgeability of implementing […]

Generating Random Numbers C#

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 of the Random Generator (Random class in C#). While this makes sense, there is no […]