title: C# Only one compilation unit can have top-level statements
body: <p>I just started learning c#, I created C# console application. To understand the concepts, I watched videos of <strong>how to setup vs code for c#</strong></p>
  <p>When I run the <code>dotnet new console</code> command in VS code terminal, it creates a new project including <code>Program.cs</code> file.</p>
  <p>In the video, the <code>Program.cs</code> file appears like that</p>
  <pre class="lang-cs prettyprint-override"><code>// Program.cs
  using System;
  namespace HelloWorld
  {
    class Program
    {
      static string Main(string[] args)
      {
        Console.WriteLine(&quot;Hello, World!&quot;);
      }
    }
  }
  </code></pre>
  <p><code>Program.cs</code> in my IDE appears like,</p>
  <pre class="lang-cs prettyprint-override"><code>// Program.cs
  // See https://aka.ms/new-console-template for more information
  Console.WriteLine(&quot;Hello, World!&quot;);
  </code></pre>
  <p>When I run the code using terminal <code>dotnet run</code> it runs perfectly on my computer.</p>
  <p>when I create a new cs file, it contains</p>
  <pre class="lang-cs prettyprint-override"><code>// hello.cs
  Console.WriteLine(&quot;hello world&quot;);
  </code></pre>
  <p>after running it says  <code>Only one compilation unit can have top-level statements. </code></p>
  <p>when I use class method and namespace like</p>
  <pre class="lang-cs prettyprint-override"><code>// hello.cs
  namespace helloworld
  {
      class hello
      {
          static void Main()
          {
              Console.WriteLine(&quot;hello world&quot;);
  
          }
      }
  }
  </code></pre>
  <p>it runs THE <code>Program.cs</code> file not the new file and shows this warning</p>
  <blockquote>
  <p><code>PS C:\Users\User\C#projects&gt; dotnet run hello.cs C:\Users\User\C#projects\hello.cs(5,21): warning CS7022: The entry point of the program is global code; ignoring 'hello.Main()' entry point. [C:\Users\User\C#projects\C#projects.csproj]   Hello, World!</code></p>
  </blockquote>
  <p><strong>Project structure:</strong></p>
  <p><a href="https://i.stack.imgur.com/1PiX8.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/1PiX8.png" alt="enter image description here" /></a></p>
  <p>I tried another method by pressing <code>run and debug</code> and show nothing.</p>
  <p>When I click on <em>Generate c# Assets for Build and Debug</em> button it shows this</p>
  <blockquote>
  <p>Could not locate .NET Core project. Assets were not generated.</p>
  </blockquote>