Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

dart
communitycreator

What is the main() function in Dart?

Maria Elijah

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

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.

Syntax

void main()
{
    //main() function body 
}

Parameters

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.

Return

The main() function returns void.

Code

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 length
print(params.length);
//print the list
print(params);
}

RELATED TAGS

dart
communitycreator

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring