add C# version

based upon the C version (but I haven't verified that the output matches for a given input)