Learn
Now that you’re familiar with classes, you’re ready to tackle the Main()
method, the entry point for any program. You’ve seen it many times, but now you can explain every part!
class Program { public static void Main (string[] args) { } }
Main()
is a method of theProgram
class.public
— The method can be called outside theProgram
class.static
— The method is called from the class name:Program.Main()
.void
— The method means returns nothing.string[] args
— The method has one parameter namedargs
, which is an array of strings.
Main()
is like any other method you’ve encountered. It has a special use for C#, but that doesn’t mean you can’t treat it like a plain old method!
Instructions
1.
Each time we run dotnet run
, the Main()
method is called. We can include arguments on the command line, like dotnet run arg1 arg2 arg3
that will be converted into an array as the args
parameter. In the console, enter:
dotnet run mango pineapple lychee
Based on this new information, how is your text printed to the console?
Take this course for free
By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.