Category Archives: C#

Foreach is Duck Typed!

I thought I know how the foreach construct worked under the covers. I figured the compiler would check if the type being iterated over implement IEnumerable or IEnumerator.  And if so it will call MoveNext and Current to loop over … Continue reading

Posted in C# | Leave a comment

ArgumentNullException vs ArgumentException

Both ArgumentNullException and ArgumentException have a constructor which takes two strings.  One is the name of the parameter (or argument) in question and the other is a string describing the exception. The funny/odd/interesting thing about them is that one has … Continue reading

Posted in C# | Leave a comment

Closures and Pass by Reference

What do you think the following code will do? Compile time error Run time error Work fine 1: static void Main(string[] args) 2: { 3: int x = 10; 4: int y = 5; 5: Swap(ref x, ref y); 6: … Continue reading

Posted in C# | Leave a comment

Covariance and Contravariance

I just finished reading the series of ten blog posts by Eric Lippert about covariance and contravariance.  These topics were new to me but after reading this blog series it all made sense.  It finally explained to me why some … Continue reading

Posted in C# | Leave a comment

Lazy Prime Number Sieve in C#

In my last post I talked about a Stream class for creating efficient lazy lists in C#.  In addition, I showed several classic functional methods I ported to C# to be used on the lazy lists.  As I mentioned in … Continue reading

Posted in C# | Leave a comment

Digging deeper into C# Lazy Lists

One of the most interesting aspects of the Haskell language is the fact that features lazy evaluation.  My interest in lazy evaluation led me to a post on Wes Dyers blog about lazy lists in C#.  In his blog post … Continue reading

Posted in C# | Leave a comment

Understanding Variable Capturing in C#

With the addition of anonymous delegates in C# 2.0 and with lambda expressions in C# 3.0 you might have been hearing a lot about variable capturing.  This is the mechanism in which the delegate/lambda which was defined inline is able … Continue reading

Posted in C# | Leave a comment

Who would have thunk it?

I recently read this article about Lazy Computation in C#. What the article discusses is creating lazy evaluation in C#. Lazy evaluation is a key feature of functional languages like Haskell but is not common in imperative languages.  It is … Continue reading

Posted in C#, Haskell | Leave a comment

Did you know…. Generic Methods

Did you know that you can call a generic method with out supplying the type argument.  The C# compiler will fill in the type parameter for you at compile time since the language is strongly typed. static void MyMethod<S>(S myParam) … Continue reading

Posted in C# | Leave a comment

Lambda Expressions

With the release of C# 3.0 and Visual Basic 9, both languages added support for lambda expressions. Lambda expressions form the basis of lambda calculus which (this will seem a bit mathy) is a formal system which is used to … Continue reading

Posted in C# | Leave a comment