From cbf8a43ca14fe063b42f2d7a209a6f7139e7cd5e Mon Sep 17 00:00:00 2001 From: Sridhar Easwaran Date: Fri, 11 Oct 2019 20:29:26 +0530 Subject: Add example for Optional Positional Parameter --- dart.html.markdown | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'dart.html.markdown') diff --git a/dart.html.markdown b/dart.html.markdown index 07f755f7..fb1856fd 100644 --- a/dart.html.markdown +++ b/dart.html.markdown @@ -503,6 +503,17 @@ example30() { } } +// Optional Positional Parameter +// parameter will be disclosed with square bracket [ ] & square bracketed parameter are optional. +example31() { + findVolume(int length, int breath, [int height]) { + print('length = $length, breath = $breath, height = $height'); + } + + findVolume(10,20,30); //valid + findVolume(10,20); //also valid +} + // Programs have only one entry point in the main function. // Nothing is expected to be executed on the outer scope before a program // starts running with what's in its main function. @@ -514,7 +525,7 @@ main() { example8, example9, example10, example11, example12, example13, example14, example15, example16, example17, example18, example19, example20, example21, example22, example23, example24, example25, example26, - example27, example28, example29, example30 + example27, example28, example29, example30, example31 ].forEach((ef) => ef()); } -- cgit v1.2.3 From 092b9155bede1cfe3dcec9b130823348b2d04e7f Mon Sep 17 00:00:00 2001 From: Sridhar Easwaran Date: Fri, 11 Oct 2019 22:28:57 +0530 Subject: Update dart.html.markdown --- dart.html.markdown | 37 ++++++++++++++++++++++++++++++++----- 1 file changed, 32 insertions(+), 5 deletions(-) (limited to 'dart.html.markdown') diff --git a/dart.html.markdown b/dart.html.markdown index fb1856fd..ce6f681b 100644 --- a/dart.html.markdown +++ b/dart.html.markdown @@ -503,15 +503,42 @@ example30() { } } -// Optional Positional Parameter +// Optional Positional Parameter: // parameter will be disclosed with square bracket [ ] & square bracketed parameter are optional. example31() { - findVolume(int length, int breath, [int height]) { + findVolume31(int length, int breath, [int height]) { print('length = $length, breath = $breath, height = $height'); } - findVolume(10,20,30); //valid - findVolume(10,20); //also valid + findVolume31(10,20,30); //valid + findVolume31(10,20); //also valid +} + +// Optional Named Parameter: +// parameter will be disclosed with curly bracket { } +// curly bracketed parameter are optional. +// have to use parameter name to assign a value which separated with colan : +// in curly bracketed parameter order does not matter +// these type parameter help us to avoid confusion while passing value for a function which has many parameter. +example32() { + findVolume32(int length, int breath, {int height}) { + print('length = $length, breath = $breath, height = $height'); + } + + findVolume32(10,20,height:30);//valid & we can see the parameter name is mentioned here. + findVolume32(10,20);//also valid +} + +// Optional Default Parameter: +// same like optional named parameter in addition we can assign default value for this parameter. +// which means no value is passed this default value will be taken. +example33() { + findVolume33(int length, int breath, {int height=10}) { + print('length = $length, breath = $breath, height = $height'); + } + + findVolume33(10,20,height:30);//valid + findVolume33(10,20);//valid } // Programs have only one entry point in the main function. @@ -525,7 +552,7 @@ main() { example8, example9, example10, example11, example12, example13, example14, example15, example16, example17, example18, example19, example20, example21, example22, example23, example24, example25, example26, - example27, example28, example29, example30, example31 + example27, example28, example29, example30, example31, example32, example33 ].forEach((ef) => ef()); } -- cgit v1.2.3