I found this to be the easiest and most readable implementation. You don't have to think while reading it. Casting always makes me think.