//positional parameter cf.positional은 required가 default이다.
String P_sayHello(String name, int age, String country) {
return "Hello $name, you are $age, and you come from $country";
}
//named parametre
String N_sayHello({String name, int age, String country}) {
return "Hello $name, you are $age, and you come from $country";
}
//required
String R_sayHello({
required String name,
required int age,
required String country
}) {
return "Hello $name, you are $age, and you come from $country";
}
//default values
String D_sayHello({
String name = 'nico',
int age = 12,
String country = 'cuba',
}) {
return "Hello $name, you are $age, and you come from $country";
}
void main() {
print(P_sayHello("nico",'cuba",12); //positional parameter(recommend max 2 params.))
print(N_sayHello(
age : 12,
country : 'cuba',
name : 'nico',
));
print(R_sayHello()) //required:won't be compiled
print(D_sayHello( //default values:Okay without some values.
age : 99
));
}
'스터디 > Dart' 카테고리의 다른 글
[Dart] #3.4 QQ Operator ?? and ??= (0) | 2024.01.10 |
---|---|
[Dart] #3.3 Optional Positional Parameters (0) | 2024.01.10 |
[Dart] #3.1 Named Parameters ({ }) (0) | 2024.01.10 |
[Dart] #3.0 Functions (0) | 2024.01.10 |
[Dart] #2.5 Sets (0) | 2024.01.10 |