Professional Documents
Culture Documents
Notes Lecture 15 Optional Named Parameter
Notes Lecture 15 Optional Named Parameter
In Dart optional parameters are divided into three different categories and we have already covered other two
categories.
Named Parameters help to avoid the errors if there are a large number of parameters
A curly bracket is placed around the named parameters. Here breadth and height are named parameters.
and this is how named parameter function is invoked. For the first parameter there is jus literal value but for
the 2nd and 3rd parameter names are written as these two variable are named parameter in the function.
var result=findVolume(3,breadth:6,height:9);
var result=findVolume(3,height:9,breadth:6);
Breadth value will be assigned to the breadth parameter as it is recognized by its name. Time to complete the
cuboid volume example.
void main() {
var result=findVolume(3,breadth:6,height:9);
print(result);
print("");
//Changing the parameter's sequence
var result2=findVolume(3,height:9,breadth:6);
print(result2);
}
int findVolume(int length, {int breadth, int height}) {
return length*breadth*height;
}
Output
162
162