The main()
function is a top-level function in Dart that initiates the execution of the program. It is the Dart programming language’s most important and crucial feature. In a program, the main()
function can only be used once.
The main()
function is responsible for all kinds of execution, including user-defined statements, functions, and libraries. The program starts with the main()
function, which contains variable declarations, functions, and user-defined executable statements.
void main()
{
//main() function body
}
An optional List <String>
parameters may be used as function arguments. These parameters can be used if we need to influence our application from the outside.
The main()
function returns void
.
The code below shows a basic example of the use of main()
function in Dart.
main(){print("Welcome! This is a shot on main() function in Dart");}
The code below shows how to pass arguments inside the main()
function.
main(List<String> params){var params =["a","p","e"];//print the lengthprint(params.length);//print the listprint(params);}