As you already mentioned, maybe they are trying to detect when it Offsetwraps to zero (or goes negative) and keeps it tied to the maximum value for any type Offset. Or they may try to cope with a situation where Offset"at the same time" increases in several threads (or something else).
In any case, this is an erroneous code.
If they try to detect / prevent wrapping to zero or a negative value, too many increments will cause a problem. If they try to figure it out Offsetwhile increasing at the same time, Iām not sure what problem they are really trying to solve or how they are trying to solve it.
Here are the problems:
As John Skeet says :
- Offset , .
, Offset volatile, Offset , , Max() Offset ( ). , , Offset, .
, Offset - ( , , ). Offset . Max(), , , .
Max(Threading.Interlocked.Increment(Offset), Offset - 1)
, ( ), - .
, Google , , (?) # VB.NET. ( ). , Offset , , ( "", ). Offset++ ( , , # Offset++ VB.NET - . http://www.telerik.com/community/forums/open-source-projects/code-converter/added-value.aspx#307755). Offset++ , , , .
, : ", Interlocked.Increment()".