Created
June 7, 2022 15:33
-
-
Save DeoEsor/afa53c5bcaeb55a0296ab58422c8d357 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class Server | |
{ | |
private static int _count = 0; | |
private static readonly object Lock = new object(); | |
public static void AddToCount(int value) | |
{ | |
lock (Lock) | |
_count += value; | |
} | |
public static int GetCount() | |
{ | |
lock (Lock) | |
return _count; | |
} | |
} | |
namespace Var2 | |
{ | |
public static class Server | |
{ | |
private static int _count = 0; | |
public static void AddToCount(int value) => Interlocked.Add(ref _count, value); | |
public static int GetCount() => _count; | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment