Is the ternary operator (?:) thread safe in C#?
Consider the following two alternatives of getting the higher number between currentPrice and 100 ... int price = currentPrice > 100 ? currentPrice : 100 int price = Math.Max(currentPrice, 100) I raised this question because I was thinking about a context where the currentPrice variable could be edited by other threads. In the first case... could price obtain a value lower than 100 ? I'm thinking about the following: if (currentPrice > 100) { //currentPrice is edited here. price = currentPrice; } It is not threadsafe. ?: is just shortcut for normal if , so your if sample is equivalent to ? one