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

SQL Server 2005 Database Mirroring

Customers often raise the following concerns and questions regarding the Database Mirroring feature of SQL Server 2005. In here, Don Vilen a Program Manager for SQL Server Database Mirroring and I have responded to some of these concerns and questions: 1) performance – synchronous mirroring has well documented performance statistics  for instance index rebuild takes…

3

How to maintain state in a data-driven unit test

Imagine you need to maintain a list of processed data rows in a running data-driven unit test. Well, you can use the code below as a starting point: [DataSource(   “System.Data.SqlClient”, “Data Source=.;Initial      Catalog=FeatureDemo;Integrated Security=True”,   “Person”,   DataAccessMethod.Sequential),   TestMethod(),]public void Test(){   if (!TestContext.Properties.Contains(“Session”))   {      TestContext.Properties[“Session”] = Guid.NewGuid();   }   Guid session = (Guid)TestContext.Properties[“Session”];   // Now add your unit test code here   // …} TestContext is the way to go in…


SQL Server 2005 Compact Edition is now available

SQL Server 2005 Compact edition runs as an in-process application, with a very small footprint  (less than 2 MB disk footprint) offering you a good subset of the T-SQL features, and replication features of a full blown SQL install. DB Size is capped at 4GB, should you want to be able to deal with that…

1

Use of string.Format for the purpose of tracing

Application tracing is usually turned off on production releases. Therefore it is recommended not to use string formatting methods if their output is being ignored. string.Format is usually an expensive method and should be avoided if its output is not consumed: Log.Write(string.Format(“User {0} tried to log on at {1}”, userName, logonTime)); Many tracing and logging…


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…