C# solution using Monitor lock
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nusing System.Threading;\npublic class ZeroEvenOdd {\n    private int n;\n    private int i;\n    private object mutex = new object();\n    private int turn = 0;\n    \n    public ZeroEvenOdd(int n) {\n        this.n = n;\n        i=1;\n    }\n\n    // printNumber(x) outputs "x", where x is an integer.\n    public void Zero(Action<int> printNumber) {\n\n        while(i<=n){\n            lock(mutex){\n\n            while(turn!= 0 && i<=n){\n                Monitor.Wait(mutex);\n            }\n\n            if(i>n){\n                break;\n            }\n            printNumber(0);\n            turn = (i%2)==0?2:1;\n            Monitor.PulseAll(mutex);\n        }\n        }\n        \n    }\n\n    public void Even(Action<int> printNumber) {\n\n        while(i<=n){\n            lock(mutex){\n            while(turn!=2 && i<=n){\n                 Monitor.Wait(mutex);\n            }\n            if(i>n){\n                break;\n            }\n            printNumber(i++);\n            turn =0;\n            Monitor.PulseAll(mutex);\n        }\n        }\n        \n    }\n\n    public void Odd(Action<int> printNumber) {\n\n        while(i<=n){\n            lock(mutex){\n            while(turn!=1 && i<=n){\n                 Monitor.Wait(mutex);\n            }\n            if(i>n){\n                break;\n            }\n            printNumber(i++);\n            turn =0;\n            Monitor.PulseAll(mutex);\n        }\n        }\n        \n    }\n}\n```
['C#']