Casting in .NET via object mutation
In this post, we will see how to make the following code fail: object it = new SomeStruct { Item = 1 }; Floatsy(it); Console.WriteLine(((SomeStruct)it).Item); At runtime, it will throw an InvalidCastException!
In this post, we will see how to make the following code fail: object it = new SomeStruct { Item = 1 }; Floatsy(it); Console.WriteLine(((SomeStruct)it).Item); At runtime, it will throw an InvalidCastException!
Today, thanks to user Lucero on StackOverflow, I learned about .NET’s “Balancing Groups” Regex feature. Basically, any time you use a named capturing group, it actually pushes the capture onto a named stack. You can then pop this stack by using the same capturing group prefixed with a hyphen, like (?< -stackToPop>). Of course, anyone [...]
So, Colin Percival has posted a UTF-8 strlen which improves on my previous post. While his code runs slightly slower than mine on my PC, I assume that’s because his code is aimed at a 64-bit architecture. With 32-bits (reading 4 bytes at a time, instead of 8 ) it doesn’t quite get the same [...]
Douglas, you’re not alone. import Data.List (sortBy) import Data.Function (on) import Data.Maybe (mapMaybe) import Control.Monad.Instances gizzabuzz pairs combiner = zipWith ($) (cycle funcs) [1..] where sortedPairs = sortBy (compare `on` fst) pairs funcs = map (\n -> display $ mapMaybe (filterOut n) sortedPairs) [1..foldr1 lcm $ map fst $ sortedPairs] display [] = show [...]