title: Cannot access non-static field in static context
body: <p>I am getting an error when coding in Visual Studio 2010 stating <code>Cannot access non-static field _cf in static context</code>, can somebody please explain why I am getting this message and if possible how to resolve this issue?</p>
  
  <p><strong>CommonFunctions.cs</strong></p>
  
  <pre><code>namespace WebApplication1.Functions
  {
      public class CommonFunctions
      {
          public string CurrentUser()
          {
              string login = HttpContext.Current.User.ToString();
              string[] usplit = login.Split('\\');
              string name = usplit[1];
              return name;
          }
      }
  }
  </code></pre>
  
  <p><strong>Team.aspx.cs</strong></p>
  
  <pre><code>namespace WebApplication1
  {
      public partial class Team : System.Web.UI.Page
      {
          private readonly CommonFunctions _cf = new CommonFunctions();
  
          public string CurrentUser = _cf.CurrentUser();
  
          protected void Page_Load(object sender, EventArgs e)
          {
              if (!string.IsNullOrEmpty(CurrentUser))
              {
                  // Do stuff here
              }
              else
              {
                  // Do other stuff here
              }
          }
      }
  }
  </code></pre>
  
  <p>I can put the <code>CurrentUser</code> code direct into the <code>protected void Page_Load</code> function but as I need to reuse <code>CurrentUser</code> throughout the project it seems ludicrous to replicate.</p>
  
  <p>Any help would be much appreciated :-)</p>