-4

enter image description here

Please help me on this error....I get when trying to run the code above in the link

MethodMan
  • 18,625
  • 6
  • 34
  • 52
Erin
  • 1
  • Dont paste external links. Please use snippet – Rajkumar Somasundaram Nov 28 '17 at 05:53
  • @Erin I would read up on how to code C# basics you cannot create an entry point in your code this way.. is this a Console App..? you're Main should look like this `static void Main(string[] args)` also should be inside a Class not directly under `namespace{ }` here some tutorials you can read http://www.completecsharptutorial.com/basic/main-method/ – MethodMan Nov 28 '17 at 05:55
  • Surround everything by either `static class Program { ... }` or `public class Program { ... }` depending on your needs. – Keyur PATEL Nov 28 '17 at 05:57
  • 2
    Simply move `static void Main() {}` into a class. – Sebastian Hofmann Nov 28 '17 at 05:59
  • 2
    Possible duplicate of ["A namespace cannot directly contain members such as fields or methods" in Net.Reflector](https://stackoverflow.com/questions/21175781/a-namespace-cannot-directly-contain-members-such-as-fields-or-methods-in-net-r) – mjwills Nov 28 '17 at 06:03
  • Main Function Needs to be moved in a class before execution as it can not be directly used in a namespace as suggested by @mjwills and Sebastian . – OshoParth Nov 28 '17 at 06:07

1 Answers1

3

A namespace is a collection of classes.

And since static void is a method, it throws an error. So you need to move it like this:

namespace EmployeeProgram
{
  public class employee
   {
      [STAThread]
      static void Main()
      {}
   }
}
Willy David Jr
  • 8,604
  • 6
  • 46
  • 57