
- Dart Programming Tutorial
- Dart Programming - Home
- Dart Programming - Overview
- Dart Programming - Environment
- Dart Programming - Syntax
- Dart Programming - Data Types
- Dart Programming - Variables
- Dart Programming - Operators
- Dart Programming - Loops
- Dart Programming - Decision Making
- Dart Programming - Numbers
- Dart Programming - String
- Dart Programming - Boolean
- Dart Programming - Lists
- Dart Programming - Lists
- Dart Programming - Map
- Dart Programming - Symbol
- Dart Programming - Runes
- Dart Programming - Enumeration
- Dart Programming - Functions
- Dart Programming - Interfaces
- Dart Programming - Classes
- Dart Programming - Object
- Dart Programming - Collection
- Dart Programming - Generics
- Dart Programming - Packages
- Dart Programming - Exceptions
- Dart Programming - Debugging
- Dart Programming - Typedef
- Dart Programming - Libraries
- Dart Programming - Async
- Dart Programming - Concurrency
- Dart Programming - Unit Testing
- Dart Programming - HTML DOM
- Dart Programming Useful Resources
- Dart Programming - Quick Guide
- Dart Programming - Resources
- Dart Programming - Discussion
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Dart Programming - Parameterized Function
Parameters are a mechanism to pass values to functions. Parameters form a part of the function’s signature. The parameter values are passed to the function during its invocation. Unless explicitly specified, the number of values passed to a function must match the number of parameters defined.
Let us now discuss the ways in which parameters can be used by functions.
Required Positional Parameters
It is mandatory to pass values to required parameters during the function call.
Syntax
Function_name(data_type param_1, data_type param_2[…]) { //statements }
Example
The following code snippet declares a function test_param with two parameters namely, n1 and s1
It is not mandatory to specify the data type of the parameter. In the absence of a data type, the parameters type is determined dynamically at runtime.
The data type of the value passed must match the type of the parameter during its declaration. In case the data types don’t match, the compiler throws an error.
void main() { test_param(123,"this is a string"); } test_param(int n1,String s1) { print(n1); print(s1); }
The output of the above code is as follows −
123 this is a string