Jasraj Pannu
Jasraj Pannu

Reputation: 21

Why return statement is not working in this dart program?

MY Code:

String fun(int age, String name)
{
  print("hi");
  return 'My name is $name and i am $age';
}

void main()
  {
   print("Hello! Good Morning good people.");
   fun(21,"Jasraj");   
  }

Output:

Hello! Good Morning good people. hi

My Question: Why return statement is not working?

See Image

Upvotes: 2

Views: 98

Answers (2)

Alexander Mosomi
Alexander Mosomi

Reputation: 1

in void main, return only works if you print it so print(fun(Int variable, String Variable))

Upvotes: 0

Md. Yeasin Sheikh
Md. Yeasin Sheikh

Reputation: 63864

fun return a string and to show, you need to wrap with print method.

void main() {
  print("Hel`enter code here`lo! Good Morning good people.");
  print(fun(21, "Jasraj"));
}

Or

  String result = fun(21, "Jasraj");
  print(result);

Upvotes: 3

Related Questions