Last active
December 29, 2016 12:33
-
-
Save antonfirsov/ea30e8c68bca20308a97c469929d51bf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct SuchMutableStruct | |
{ | |
public Matrix99x42 SoState; | |
public bool IsInvalid { get; private set; } | |
public bool Invalidate() | |
{ | |
IsInvalid = true; | |
} | |
} | |
public class StructUserClass | |
{ | |
public PropertyPlz { get; } | |
public void DoDangerousOperation() | |
{ | |
if (PropertyPlz.IsInvalid) | |
{ | |
throw new Exception("Ooops I should not do this now"); | |
} | |
} | |
} | |
public class Main | |
{ | |
public static void DoNaiveStuffFollowing2003sDoctrines() | |
{ | |
StructUserClass c = new StructUserClass(); | |
c.PropertyPlz.Invalidate(); | |
c.DoDangerousOperation(); // Does this throw an exception? :P | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Let me guess, when you do invalidate you are doing it on a copy of the struct? So, no to the exception.
PS: I am finding this puzzles incredibly fun 😄