What is Function in Dart
In this article, I will describe about dart function.
Function in dart language
Function is a self-contained program segment that carries out some well defined specific task.
Syntax of function
returnType functionName(arguments)
{
//
Body
//
} |
Example of function
void main()
{
Say()
{
return "I am a user defined function!";
}
Says() => 'I am also a user defined function';
print(Say());
print(Says());
}
|
output
You can used (=>) syntax , instead of return statement.
The dart function contains different type of parameter-
Example of Optional parameters
void main()
{
Say(value, to, [from]) => '${from} ${value} from ${to} ';
print(Say('comes','optionalParameter'));
}
|
Output
- Named Parameter
Optional parameter are also named parameter.
Example of named parameter
void main()
{
Say(value, to, [from]) => '${from} ${value} from ${to} ';
print(Say('comes','namedParameter','from:sharad'));
}
|
Output
Got a programming related question? You may want to post your question here