What do the first few lines of most pieces of C# code mean?

224 viewsOtherTechnology

e.g. “using System;” , “namespace MyApplication” , “class Program” , “static void Main(string\[\] args)” and what classes and namespaces are

In: Technology

5 Answers

Anonymous 0 Comments

It’s hard to explain these things while staying ELI5 because what you should be looking for is an introduction to C#.

Classes are like folders where the code is organized in “methods” and “attributes”.

A namespace is like a prefix to the class name. It is used to prevent conflicts. In a huge application with a lot of libraries you will likely end up with two classes of the same name. You use their namespace to differentiate them like so: NamespaceA.MyClass and NamespaceB.MyClass.

If you are only using one version of MyClass and you do not want to type NamespaceA.MyClass everytime, you can add “using NamespaceA” and it will know which namespace to use when referencing MyClass.

“static void Main(string[] args)” is the entry point of your program. When you launch the application this is what your operating system will call first.

You are viewing 1 out of 5 answers, click here to view all answers.