title: Why can't I cast an integer to an enumeration
body: <p>I am trying to cast an integer from a DataGridViewRow cell value which I have confirmed equals <code>0</code></p>
  
  <p><code>AddedTask.Status = (TaskStatus) row.Cells["status"].Value;</code></p>
  
  <p><a href="https://i.stack.imgur.com/Ifq5p.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Ifq5p.jpg" alt="InvalidCastException in Visual Studio"></a></p>
  
  <p>Here is the code that creates the Task object and the TaskStatus Enum.</p>
  
  <pre><code>class Task
  {
      public string Description { get; set; }
  
      public TimeSpan Duration
      {
          get
          {
              if (BeginDate == DateTime.MinValue) // BeginDate has not been set
                  return new TimeSpan(0, 0, 0);
              else if (EndDate == DateTime.MinValue)
                  return DateTime.Now.Subtract(this.BeginDate);
              else
                  return this.EndDate.Subtract(this.BeginDate);
          }
      }
  
      public DateTime BeginDate { get; set; }
      public DateTime EndDate { get; set; }
      public TaskStatus Status { get; set; }
  
      public Task()
      {
          this.Description = string.Empty;
          this.BeginDate = new DateTime();
          this.EndDate = new DateTime();
          this.Status = TaskStatus.UNINVOICED;
      }
  }
  
  public enum TaskStatus
  {
      UNINVOICED,
      INVOICED,
      PAID
  }
  </code></pre>