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

226 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

`using System` says “there is a library, called **System** that I will be **using** so load it”. in this case the print function is in system

`namespace whatever;` says “to avoid confusion elsewhere, make me a namespace, and put the following in it” a namespace is exactly what it sounds. a space for names. in your daily life you intuitive use namespaces. if I tell you “Will from work” or “Will from highschool” you know they are different Wills. the from tells you the namespace I am using so you don’t get confused about which Will and everyone doesnt need their own unique name.

`class Program` makes a class called program. you will learn more about classes later, for now just know they are re-usable bundles of functions and data that c# requires you to use even if you dont need.

the last line is the program entry point. it defines a function that exact function is what your computer is looking for when you run a c# program. `static` says “take all the cool stuff about classes and stuff it up your ass. this function doesn’t use any of it, basically its just a namespace to me” `void` says “this function isn’t going to return a value” (like int add(int x, int y) is going to return an integer) `Main` is the function name. in this case it has to be `Main` because that is what c# is looking for. `()` says “this is a function” and in between are the arguments to the function. `string[] args` is the 1st argument to main, it is called “args” but could be called whatever you want. it is of type `string[]`. `[]` means it is an array (multiple values in a 1 variable (in an order)) and `string` means its text. when you call a program from command line, that entire command is passed to main in args. so `cp here there` is passed as `[“cp”,”here”,”there”]` to the program `cp` program.

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