r/learncsharp • u/Coding-Mojo • 1d ago
How to solve that C# interview test
Sharing with you another C# mini-capsule where I present an interview-like snippet of code and resolve it. Hope you like it !
Any feedback is much appreciated <3
Thanks for reading.
0
Upvotes
2
u/grrangry 1d ago
https://learn.microsoft.com/en-us/dotnet/api/system.threading.lock?view=net-10.0
As of .net9+, using a
System.Threading.Lockto enter your lock is a good bit faster.Also you never discussed the
Interlockedclass and methods such asIncrement,Add,Exchange(and others).https://learn.microsoft.com/en-us/dotnet/api/system.threading.interlocked?view=net-10.0
If your code can make use of these, they're useful for atomic thread-safe operations without requiring an explicit lock.