Skip to content

Instantly share code, notes, and snippets.

@antonfirsov
Last active December 29, 2016 12:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save antonfirsov/ea30e8c68bca20308a97c469929d51bf to your computer and use it in GitHub Desktop.
Save antonfirsov/ea30e8c68bca20308a97c469929d51bf to your computer and use it in GitHub Desktop.
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
}
}
@olivif
Copy link

olivif commented Dec 29, 2016

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 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment