i++; is a very useful piece of code but it doesn’t always act how people expect. This was highlighted when a friend asked me about it today. He had the following code: int i = 0; int j = i++; He wanted both i and j to be incremented and thought that the ++ syntax … More i++;

C# Variable Scope

Saw an interesting error crop up in Visual Studio today: “A local variable named ‘foo’ cannot be declared in this scope because it would give a different meaning to ‘foo’, which is already used in a ‘child’ scope to denote something else”. I never knew that child scopes could be affected by a variable defined … More C# Variable Scope

MySQL in a .NET App

When you have the MySQL .NET library installed on a local machine and want to deploy an Entity Framework application to a server without the library installed, I always (thus-far without fail) forget at least one of the following: EntityFramework.dll – set to copy local MySql.Data.dll – set to copy local MySql.Data.Entity.dll – set to … More MySQL in a .NET App

C# Code Snippets

Snippets live in C:Users[YOUR_NAME]DocumentsVisual Studio [VERSION]Code SnippetsVisual C#My Code Snippets Place the following into the above folder: fn.snippet. Also, find attached an MVC action snippet: actn.snippet. Find these on GitHub here.

Named String Formatting

Phil Haack has written a few interesting articles about how to do a string format with text keys as opposed to indexes ({name} instead of {0}). See the original article and where he revisits the topic with even better results. The final result is a few extension methods which can be run like so: string pattern = … More Named String Formatting