How to design a Priority Queue in C#

What is a Priority Queue? To be a bit formal, a priority queue is an abstract data type (ADT), similar to a regular queue, but where each element has a priority associated to it. An element with high priority is served before an element with a low priority. Elements which have the same priority are […]

Book Review – The imposter’s handbook

Introduction Just by reading the heading of this blog post won’t tell you anything about what kind of book I am writing a review on. The full title is actually The imposter’s Handbook – A CS Primer For Self-Taught Programmers, where CS is short for Computer Science. The book is written by Rob Conery, a […]

C# struct and class – when to use each?

Value types and Reference types In C# you have both Value types and Reference types. There are some fundamental differences between them that are important to understand. The most common value types are the simple ones, like int, bool, char, and long. But also enum and struct are value types. They are called value types […]

C# Protecting private collections from modification – Part 2

The common object issue In the last part I wrote about how you can protect a class’s private collections from modification by wrapping them in a ReadOnlyCollection before exposing them. But how about collections that are handed to your class? Consider the following code: What happens here is that MyClass takes a variable of reference […]