The .NET Core framework provides a variety of collections with which we can use LINQ queries. As a developer, there are far fewer options when looking for thread-safe collections. Without thread-safe collections, it can become difficult for developers when they have to perform multiple operations. In this case, we would meet the race condition that we have already discussed in Chapter 4, Implementing Design Patterns - Basics Part 2. To overcome such situations, we need to use the lock statement, as we have used in the previous section. For example, we can write a code of a simplified implementation of the lock statement—refer to the following code snippet, where we have used the lock statement and collection class, Dictionary:
public bool UpdateQuantity(string name, int quantity)
{
lock (_lock)
{
_books[name].Quantity += quantity;
...