title: c# accessing struct members within class' methods
body: <p>i'm trying to write a simple game. I want to design a "movement controller" object, that would handle move instructions from the engine. I would also like for this object to expose a method, that would check its state and return true/false depending if it's ready to move or not. The state will be saved as group of boolean variables. Since there is a lot of them, I decided to group them together in a new struct called "flags". This is how it looks like more or less:</p>
  
  <pre><code>public class movContr
  {
      int movId;
      public struct flags
      {
          bool isMoving;
          bool isLocked;
          bool isReady;
          (...)
      }
  
      public bool CheckReadiness()
      {
          if(flags.isReady==true) return true;
          return false;
      }
  }
  </code></pre>
  
  <p>Now the problem is this won't compile, error being:</p>
  
  <pre><code>error CS0120: An object reference is required to access non-static member
  </code></pre>
  
  <p>offending line being:</p>
  
  <pre><code>if(flags.isReady==true) return true;
  </code></pre>
  
  <p>So I guess C# doesn't treat structs like memory blobs that just contains variables in orders, but like some "special" cousin of a class.</p>
  
  <p>Here are my questions:</p>
  
  <p>how should I handle accessing struct class members in its methods? How can I refer in class methods to members of its future instances? I tried this instead:</p>
  
  <pre><code>if(this.flags.isReady==true) return true;
  </code></pre>
  
  <p>but i get the same error.</p>
  
  <p>Alternatively, if encapsulating my flag variables using 'struct' is not a proper way to do so, what is?</p>
  
  <p>I tried to find an answer myself but since all the keywords I could come up with are very generic, so are the results. Most deal with static members, which are not a solution here since I need multiple, independent instances of movContr class.</p>