In this tutorial you will learn about the Dart Return Values and its application with practical example.
Dart Return Values
Sometimes we may want a function to return some value to the point it where it is called from. In Dart, there is return keyword allows a function to return value. The return statement is optional, if not specified the function returns null. There can be only one return statement in a function.
Syntax:-
1 |
return <expression/value>; |
Dart Function With Return Value
Syntax:-
1 2 3 4 5 |
return_type func_name() { //Statement(s) return value; } |
func_name :- It is replaced with the name of the function.
return_type :- It represents return_type of the function. The return_type can be any valid data type. The data type of the value returned must match the return type of the function.
Example:-
1 2 3 4 5 6 7 |
String sayHelloWorld() { return "Hello, World!"; } void main(){ print("W3Adda - Dart Function With Return Statement."); print(sayHelloWorld()); } |
Output:-