C# using AutoResetEvent. Clean codes
\nusing System.Threading;\n\npublic class FooBar {\n    private int n;\n    private AutoResetEvent printFooEvent;\n    private AutoResetEvent printBarEvent;\n  
```\nusing System.Threading;\n\npublic class FooBar {\n    private int n;\n    private AutoResetEvent printFooEvent;\n    private AutoResetEvent printBarEvent;\n    public FooBar(int n) {\n        printFooEvent = new AutoResetEvent(true);\n        printBarEvent = new AutoResetEvent(false);\n        this.n = n;\n    }\n\n    public void Foo(Action printFoo) {\n        \n        for (int i = 0; i < n; i++) {\n            printFooEvent.WaitOne();\n        \t// printFoo() outputs "foo". Do not change or remove this line.\n        \tprintFoo();\n            printBarEvent.Set();\n        }\n    }\n\n    public void Bar(Action printBar) {\n        \n        for (int i = 0; i < n; i++) {\n            printBarEvent.WaitOne();\n            // printBar() outputs "bar". Do not change or remove this line.\n        \tprintBar();\n            printFooEvent.Set();\n        }\n    }\n}\n```
[]