Converting PHP code to C#?