title: Casting string value to enumerated value C#
body: <p>I have a class <code>MyClass</code> which has</p>
  
  <pre><code>public enum Days{Mon, Tue, Wed}
  </code></pre>
  
  <p>and then a field</p>
  
  <pre><code>public Days dayOfWeek;
  </code></pre>
  
  <p>From another class in my solution I have a string (<code>myString</code>) value of either <code>0</code>, <code>1</code> or <code>2</code>. I want to set an instance of <code>MyClass</code>'s (called <code>myClassInstance</code>) field <code>dayOfWeek</code> equal to <code>myStringvalue</code> such that <code>0</code> means Mon, <code>1</code> means Tue...</p>
  
  <p>I have tried</p>
  
  <pre><code>myClassInstance.dayOfWeek = Convert.ToInt32(myString)
  </code></pre>
  
  <p>and   </p>
  
  <pre><code>myClassInstance.dayOfWeek = (int) myString
  </code></pre>
  
  <p>but neither work. I'm sure this is straightforward. Why don't these techniques work?</p>