NEW: Code ported to CSharp

Code ported to CSharp