45 subscribers

C# – the language
  |  Software Dev  |  Science Stuff  |  Travel  |  Golf Tips for Beginners  |  Entertainment  |  Mindfulness  |  Finance and Investing  |  Austin  |  India  |  Diet, Health  |  Miscellaneous  |  Sports (Non Golf)  |  

Language essentials, gotchas

Binary tree (count nodes) interview question | Posted on by Anuj Varma

Given a LEFT and a RIGHT property that returns the underlying LEFT tree and the underlying RIGHT tree respectively, find the total count of the nodes in the tree. class BinaryTree<T> { private BinaryTree<T> left; private BinaryTree<T> right; public int … Continue reading

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 … Continue reading

Filesystem notes from the real world–C# | Posted on by Anuj Varma

These are just some quick tidbits about file processing in C#.  Reading in files, reading in LARGE files, Reading and Processing Large Files.   Reading a file (use a StreamReader) if (File.Exists(path)) { using (StreamReader sr = new StreamReader(path)) { … Continue reading

Using Delegates in C# | Posted on by Anuj Varma

Introduction 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 … Continue reading

The ‘params’ keyword in c# | Posted on by Anuj Varma

Introduction 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 … Continue reading

Introduction 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 … Continue reading

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

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 … 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 … 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 … 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 … Continue reading