Cunning Planning

C# Value Types are Objects

Value types in C# are Objects, but they don’t behave exactly like Objects do. A part of the reason for this is that all value types are implicitly derived from System.ValueType. public abstract class ValueType { protected ValueType(); public override bool Equals(object obj); public override int GetHashCode(); public override string ToString(); } But wait! Structs can’t derive from classes! At first glance, this seems true. You can’t for example do this:

A Short History of Sorting in C#

Recently, while reading Jon Skeet’s excellent book“C# in Depth” I came across the long and varied history of sorting in the C# language. It provides a tantalising view of how the language has evolved over the years. Apart from being a great example on C# in particular it’s also a good example on how languages have improved over the years to become more expressive, while maintaining backward compatibility with earlier versions.

C# Abstract Properties, Virtual Properties and Access Modifiers

Properties in C# are first class citizens, this means that they can be declared as abstract, virtual, private and protected. This is not the general use case though, most of the time properties are used to encapsulate fields. class Customer { public int Number { get; set; } public string Name { get; set; } } Customer customer = new Customer(); customer.Number = 9; customer.Name = "Mrs Lovett's Pie Shop"; n the example above, auto implemented properties are used to aid encapsulation.