Posts about the C# language itself, including use, abuse and features.

Equality has Symmetry

Saturday, March 17 2018 equality csharp

If we’re going to implement equality correctly, we need to consider the contract we’re implementing - what are the characteristics of a proper implementation of equality? The first characteristic we need to consider is symmetry.

Read more »

Type Miscellany

Sunday, March 05 2017 immutable-types csharp

As we near the end of this series on immutable types (for now, anyway), here’s a grab bag of things that didn’t seem to fit elsewhere.

Read more »

Testing Immutable Types

Saturday, February 25 2017 immutable-types csharp testing

As alluded to previously, having a good suite of unit tests is critical for ensuring these immutable instances do what they should - after all, there’s no point in having a queue or stack that doesn’t behave.

Read more »

Factory Methods

Saturday, February 18 2017 immutable-types csharp

Our stacks and queues don’t exist in isolation - they have to interoperate with standard framework classes and other domain constructs to be useful. For example, it is extremely useful to have some factory methods to make it easier to construct stacks and queues from existing lists and sequences.

Read more »

Queue Concatenation

Saturday, February 11 2017 immutable-types csharp

If you have a whole sequence of items you want to add to an existing IImmutableQueue<T>, it’s pretty simple to write a loop to add them all. We can make this even easier by writing a simple extension method that handles the looping on our behalf.

Read more »

Complex Queues

Saturday, February 04 2017 immutable-types csharp

As discussed last time, the solution to our performance problem is to ensure our _inbound stack doesn’t get too large before we reverse it. This means we need to reverse it early; we can’t leave reversal until it’s needed to replace _outbound.

Read more »

The Problem with the Simple Queue

Saturday, January 28 2017 immutable-types csharp

In my posts Simple Immutable Queues and Enumeration of Immutable Queues I’ve alluded to a nasty flaw that’s waiting to bite. What is that flaw, and why do we need to worry?

Read more »

Enumeration of Queues

Saturday, January 21 2017 immutable-types csharp

We previously enabled enumeration of our immutable stacks - we should do the same for our immutable queues. Unfortunately, it’s a bit more complicated this time around. (For those looking to the solution to the puzzle posed at the end of my earlier post, you’ll need to wait until next time - but read to the end of this post for a clue.)

Read more »

Reversing Stacks

Saturday, January 14 2017 immutable-types csharp

It turns out that I omitted the implementation of .Reverse() from my recent post Immutable Stacks Miscellany. Given that a friend has identified an alternative way to implement this, we’ll take a minor detour.

Read more »

Simple Queues

Saturday, January 07 2017 immutable-types csharp

Thinking about the functionality we need from a simple immutable queue, we need to easily add a new item onto the end of the queue, and to easily remove an existing item from the front of the queue.

Read more »

Older posts

Queues  30 Dec 2016
Stacks Miscellany  22 Dec 2016
Stack Equality  09 Dec 2016
Enumerating Stacks  03 Dec 2016
Stacks  19 Nov 2016
When (not) to use Var  16 Jul 2016
Semantic Types Redux  05 Jun 2016
Semantic Types in C#6  27 May 2016
Property Enhancements for C#  20 Dec 2015
Language Extensions for C#  19 May 2014
When should methods be Static?  09 Oct 2012
Of Method Naming and more  29 Sep 2012
Someone needs an intervention  16 Dec 2011
CallerInfo in C# 5  08 Dec 2011
Regions in C#  16 May 2011
Lambda expressions and Block syntax  15 Apr 2011
Parameter Attributes and more  05 Feb 2011
Elegant.Data  19 Oct 2010
Doing less with LINQ  30 Jun 2010
WCF and IList  28 May 2010
Specialist Classes  22 May 2010
Attack of the Lazy Coder  20 May 2010
A Discovery in Linq: Lookup  11 Feb 2010
Co- and Contra-Variance in .NET 3.5  15 Sep 2009
When to use Var  26 Mar 2009
Struct Weirdness  11 Feb 2009
Contravariance and Covariance at last  29 Oct 2008
Spec#  30 Apr 2008
Lambda Events  22 Mar 2008
No longer the C# we knew  21 Mar 2008
Rare C#  12 May 2007
Generics in .Net  28 Jan 2004