title: Why can't I use virtual/override on class variables as I can on methods?
body: <p>In the following example I am able to create a <strong>virtual</strong> method <code>Show()</code> in the <strong>inherited</strong> class and then <strong>override</strong> it in the <strong>inheriting</strong> class.</p>
  
  <p>I want to do the <strong>same thing</strong> with the protected <strong>class variable</strong> <code>prefix</code> but I get the error:</p>
  
  <blockquote>
    <p>The modifier 'virtual' is not valid
    for this item</p>
  </blockquote>
  
  <p>But since I can't define this variable as <strong>virtual/override</strong> in my classes, I get the compiler <strong>warning</strong>: </p>
  
  <blockquote>
    <p>TestOverride234355.SecondaryTransaction.prefix'
    hides inherited member
    'TestOverride234355.Transaction.prefix'.
    Use the new keyword if hiding was
    intended.</p>
  </blockquote>
  
  <p>Luckily when I add the <code>new</code> keyword everything <strong>works fine</strong>, which is ok since I get the same functionality, but this raises <strong>two questions</strong>:</p>
  
  <ol>
  <li><p><strong>Why I can use virtual/override for methods but not for protected class variables?</strong> </p></li>
  <li><p><strong>What is the difference actually between the virtual/override approach and the hide-it-with-new approach since at least in this example they offer the same functionality?</strong></p></li>
  </ol>
  
  <p>Code:</p>
  
  <pre><code>using System;
  
  namespace TestOverride234355
  {
      public class Program
      {
          static void Main(string[] args)
          {
              Transaction st1 = new Transaction { Name = "name1", State = "state1" };
              SecondaryTransaction st2 = 
                  new SecondaryTransaction { Name = "name1", State = "state1" };
  
              Console.WriteLine(st1.Show());
              Console.WriteLine(st2.Show());
  
              Console.ReadLine();
          }
      }
  
      public class Transaction
      {
          public string Name { get; set; }
          public string State { get; set; }
  
          protected string prefix = "Primary";
  
          public virtual string Show()
          {
              return String.Format("{0}: {1}, {2}", prefix, Name, State);
          }
      }
  
      public class SecondaryTransaction : Transaction
      {
          protected new string prefix = "Secondary";
  
          public override string Show()
          {
              return String.Format("{0}: {1}, {2}", prefix, Name, State);
          }
      }
  }
  </code></pre>