C# Port

Ported to C#