Dart Functions: Required Parameters

Vinit MepaniVinit Mepani
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.

0
Subscribe to my newsletter

Read articles from Vinit Mepani directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Vinit Mepani
Vinit Mepani

"Hello World, I'm Vinit Mepani, a coding virtuoso driven by passion, fueled by curiosity, and always poised to conquer challenges. Picture me as a digital explorer, navigating through the vast realms of code, forever in pursuit of innovation. In the enchanting kingdom of algorithms and syntax, I wield my keyboard as a magical wand, casting spells of logic and crafting solutions to digital enigmas. With each line of code, I embark on an odyssey of learning, embracing the ever-evolving landscape of technology. Eager to decode the secrets of the programming universe, I see challenges not as obstacles but as thrilling quests, opportunities to push boundaries and uncover new dimensions in the realm of possibilities. In this symphony of zeros and ones, I am Vinit Mepani, a coder by passion, an adventurer in the digital wilderness, and a seeker of knowledge in the enchanting world of code. Join me on this quest, and let's create digital wonders together!"