rewrite java code to c#