Skip to content

Instantly share code, notes, and snippets.

@DeoEsor
Created June 7, 2022 15:33
Show Gist options
  • Save DeoEsor/afa53c5bcaeb55a0296ab58422c8d357 to your computer and use it in GitHub Desktop.
Save DeoEsor/afa53c5bcaeb55a0296ab58422c8d357 to your computer and use it in GitHub Desktop.
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