Dart Functions: Required Parameters

Dart Functions: Required Parameters

ยท

1 min read

The parameter is the process of passing values to the function. Most of all the programming language has this kind of parameter.

The values passed to the function and the number of parameters must match otherwise we can face the error .

A function can have many number of parameters.


void printname(String name, String gender) {
  print("Hello $name your gender is $gender.");
}

void main() {
  // passing values in wrong order
  printname("Male", "Vinit");

  // passing values in correct order
  printname("Vinit", "Male");

}

// Hello Male your gender is Vinit.
// ello Vinit your gender is Male.

In this example , I have passed the two value in the printname() function which is name and gender than I have to must call both the value in the function whenever I run , if I call only one value at that time then I an find the error.

Order is not affect the code when both the data type is same , but if both the data type is different like one is string and other is int then we must follow the order when we call parameter. Like in the above example both data type are same that's why order does not affect the code and run successfully.

ย