In this tutorial you will learn about the Dart main() Function and its application with practical example.
Dart main() Function
This is the most vital part of each and every Dart program, it is mandatory for every Dart program to have a top-level main() function definition. There can be only one main() function in Dart program. It serves as the entry point for every Dart program or app; the execution of a Dart program or application starts with the main() function. The Dart program can not be executed without the main() function. The main() function is responsible for the execution of all the user defined statement, functions and library functions. The main() function further structured into variable declaration, function declaration and user defined executable statements. The main() function returns void and can have an optional List<String> parameter as arguments. Below is the general syntax of a typical main() function.
Syntax:-
1 2 3 |
void main() { // main function body } |
Example:-
1 2 3 |
main(){ print("W3Adda - Hello World!"); } |
Output:-