Pre-PS: Inspired by Jon Skeet's comment above, I suggest you do the following:
- (Optional: back up the current code.)
- Simplify your code by gradually removing parts of it until the warning disappears. *
- As soon as the warning disappears, you will find out which parts of your code caused the error (namely, the part that you deleted last), and then you can understand it.
( Where did this advice come from? → You already saw that you can make the warning go away by adding code. I think your understanding of the problem will be even better when you do the opposite, that is, delete the code to get to the bottom of the problem.)
main.property can only have values 0, 1, 2, and 98, and you said that your code ( CreateMain ) works correctly in this regard.
Thus, I assume that VS assumes that main.property will always be 0. Why this should come to this conclusion, I do not know. Perhaps he thinks he was not initialized.
I wrote code similar to yours and I don’t get this warning - I don’t even get a warning when I declare main.property as readonly and initialize it to 0. Thus, you probably main.property up in one of these situations when the crash code analysis / debugger VS.
Possible (though unlikely) reasons:
Is there any code path where main.property not initialized?
Since main.property is of type byte (at your discretion), maybe the warning is somehow caused by an overflow or overflow? (What happens if you change the type to int ?)
Could it be that main obscures another main variable?
stakx source share