Of course, you know the rule, don’t you. If you want to define your own value types in .NET, make sure they are immutable. Don’t create mutable value types!
Unfortunately, today, I forgot that rule. And I paid the price in a couple of hours needless debugging. Continue reading “Mutable Structs are Evil. Yes. Really.”
If you need to read binary files or binary streams, you need to know whether the file you’re reading is big-endian or little-endian.
It’s about the order that the bytes are stored in the file. For example the number 1, stored as a 32 bit integer, is 00000001, occupying 4 bytes. That means you need a sequence of four bytes in the file to store the number. If you put the byte that holds the most significant bits first, then the bytes look like this: Continue reading “Big-Endian vs Little-Endian: How Do You Remember Which is Which?”
In my last article I pointed out that Microsoft has given us no less than nine different general-purpose interfaces to perform the simple task of comparing objects to see if they are equal, or if one is greater than the other.
And I ended with a quick quiz. Could you identify those nine interfaces?
Continue reading “IEquatable and All That: The Nine Comparisons Interfaces”
My new Pluralsight course, C# Equality and Comparisons, has been published this week, bringing my total to 3 courses with the two existing courses. Math for Programmers and C# Collections Fundamentals.
C# Equality and Comparisons was largely spawned out of the earlier C# Collections course: Back in February this year, I was writing samples for that course to demonstrate making dictionaries case-insensitive. The easiest way to do that is to supply a case-insensitive equality comparer to the dictionary constructor, like this: Continue reading “C# Equality and Comparisons Published”
I’m sure most of us have been there. You have some small data type to declare, which only really contains a couple of primitives and is clearly most appropriate to exist as a struct. You put a couple of values in it, and because you’re doing this quickly and you want your code to be simple, you use auto properties. For this kind of struct there’s (hopefully) no reason not to.
And in the best traditions of those cookery programmes you see on tv, here’s one that I prepared earlier: Continue reading “AutoProperties, Structs and Constructors (C# Wishes Part 3)”
Well Christmas, that traditional time for giving has just gone past. However the TechieSimon blog has nothing to give, apart from strange blog posts. So I thought I’d be cheeky instead. To somewhat belatedly celebrate the time of giving I’m going to do some (metaphorical) asking: For the next few blog posts I’ll talk about some of the things that I’d love Microsoft to add to the C# Language.
My first wish is for a nullable dot operator. Continue reading “The Nullable Dot (Post-Xmas C# Wishes, Part 1)”
In my very first TechieSimon article, I went on about how great Open XML was. Today I’m going to prove it – by showing how a month ago, I was able to use Open XML to make an edit to a PowerPoint document that I couldn’t easily do in PowerPoint. Continue reading “Open XML – 1, PowerPoint UI – 0”
While I was writing the Maths for Programmers course, I was constructing some examples to illustrate overflow and noticed a strange pattern. I was working with the number 255, which is the biggest number that can be stored in an unsigned byte, and is represented in binary by 1111 1111. The idea was to use the unsigned byte data type and show the results of calculating 255 + 255 and 255 * 255 – both of those will cause an overflow.
Now 255 + 255 gives 510. And 255 * 255 gives 65,025. Look at what these numbers look like in binary. Continue reading “A Strange Binary Pattern”
Last time I asked you what the output would be from this code….
double zero = 0;
double minus = -1.0e-400;
double big = 1.0 / zero;
double minusBig = 1.0 / minus;
Console.WriteLine(zero == minus);
Console.WriteLine(big == minusBig);
catch (Exception ex)
Continue reading “Zero Equals What???”
Yay! My Pluralsight course on Math for Programmers has just been published.
To quote Pluralsight’s write up on their blog…
Continue reading “Math for Programmers Published!”