title: .NET Core Razor C# functions
body: <p>I'm pretty new to .NET Core (ASP.NET on the whole) and I was wondering if I'm doing anything obviously wrong when trying to create a C# function inside my View</p>
  
  <p>my view is as follows (Collections.cshtml)</p>
  
  <pre><code>&lt;h2&gt;Collections&lt;/h2&gt;
  
  &lt;div id="content"&gt;
  
      @{
          // define variables
          List&lt;string&gt; collections;
          int counter;
  
          // build list
          collections = new List&lt;string&gt;();
          collections.Add("Nothing 01");
          collections.Add("Nothing 02");
  
          // display list
          counter = 0;
          while(counter &lt; collections.Count)
          {
              &lt;p&gt;@collections[counter]&lt;/p&gt;
              counter = counter + 1;
          }
      }
  
  &lt;/div&gt;
  </code></pre>
  
  <p>That all works fine and does what I want it to do but if I try to organize it into functions or even add a basic function it breaks like bellow</p>
  
  <pre><code>@{
      // function for no reason
      public void testFunc()
      {
          string nothing;
          nothing = null;
          return;
      }
  }
  
  &lt;h2&gt;Collections&lt;/h2&gt;
  
  &lt;div id="content"&gt;
  
      @{
          // define variables
          List&lt;string&gt; collections;
          int counter;
  
          // build list
          collections = new List&lt;string&gt;();
          collections.Add("Nothing 01");
          collections.Add("Nothing 02");
  
          // display list
          counter = 0;
          while(counter &lt; collections.Count)
          {
              &lt;p&gt;@collections[counter]&lt;/p&gt;
              counter = counter + 1;
          }
      }
  
  &lt;/div&gt;
  </code></pre>
  
  <p>Just adding that function breaks it and I'm not sure why</p>