How difficult can it be to overload operator ==?

Well apparently very difficult! Today, I read article after article on blogs that suggested weird and wonderful ways of overloading the operator == in C#. Almost all of those were incorrect! So I set myself a challenge to put the record straight: Before showing you the code, a number of things to remember: –          Overriding…

4

Lambda Expressions in C#

Before being able to talk about Lambda expressions, I need to wet your appetite by touching on the difference between Expressions and Statements: i = j; while (a) f(b);   The above listing is an illustration of 2 statements. As you can see evaluation order is important when it comes to statements. 2 * a…

3

Lazy evaluation in C#

What is lazy evaluation? If you ask a functional programming enthusiast, you will probably get a reply similar to the one below: “Oh well, allow me to enlighten you: –          In lazy evaluation, computation terminates whenever any reduction order terminates. –          It requires no more steps than eager evaluation.” An English translation of the above…

5

Extension methods in C# 3.0

You can think of extension methods as the ability to add instance methods to already existing types. Having said that, I would immediately also tell you that it is just an illusion. You are not actually adding a method to an existing type. It is just a little trick that the compiler plays on you!…

5

Local variable type inference in C# 3.0

In C# 1.0 type declaration was very simple: –          Specify the type name (if an array then append [] to the end of the type) –          Follow by a local variable name Here are some examples of this: int i = 23; double[] ds = new double[] { 1.0, 2.0 }; In C# 2.0 with…

1

Non-CLS Exceptions

Many developers are not aware that according to CLR it is perfectly OK to throw exceptions which are NOT derived from System.Exception: Exceptions such as DateTime, Int64 and String. Although languages such as C# do not allows programmers to throw these types of exceptions it should still be possible to catch non-CLS compliant exceptions using…