C#

Igor Ostrovsky on April 1st, 2009

Notice that this post was published on April 1, 2009. For decades, computer science students have been taught that so-called NP-hard problems do not have known efficient solutions. These problems include the infamous Travelling salesman problem, subset sum, 3SAT, and many more. But – as is often the case – where theoretical Computer Science failed, […]

Continue reading about Choose expression: proposal for a revolutionary C# construct

Igor Ostrovsky on February 2nd, 2009

Here is a little puzzle for C# developers reading my blog. What is the error in the program below? using System.Collections.Generic; class Program { public static void Main() { int[] arr = new int[10]; IEnumerator<int> e = arr.GetEnumerator(); } }

Continue reading about Puzzling over arrays and enumerators in C#

I realized that there is a very clean way to express a multi-clause if statement by composing ternary conditional operators like this: var result = condition1 ? result1 : condition2 ? result2 : condition3 ? result4 … : conditionN ? resultN : default;

Continue reading about A neat way to express multi-clause if statements in C-based languages

Igor Ostrovsky on September 6th, 2007

Today, I am writing about a design problem related to C# generics that I’ve seen arise a few times. The problem occurs when we need to manipulate a generic class given a reference to its non-generic base class. For example, if a generic class Node<T> inherits from a non-generic class Node, and we are holding […]

Continue reading about Fun with C# generics: down-casting to a generic type