1. 함수
// 함수
void f1() {
print("f1 함수 호출");
}
void f2(int n1, int n2) {
print("f2 함수 호출됨: ${n1 * n2}");
}
int f3(int n1, int n2) {
return n1 * n2;
}
void main() {
f1();
f2(10, 20);
int result = f3(10, 5);
print("f3 함수 호출 결과: ${result}");
}
2. 람다
// 함수 : 람다 (이름이 없는 함수 축약)
// 익명함수
var f1 = () {
print("f1 함수 호출됨");
};
// 람다 문장
var f2 = () => print("f2 함수 호출됨");
// 람다 표현식
var f3 = (int n1, int n2) => n1 * n2;
// f3의 원래 함수식
int f4(int n1, int n2) {
return n1 * n2;
}
void main() {
f1();
f2();
int result = f3(10, 5);
print("f3 함수 호출 결과: ${result}");
int result2 = f4(10, 5);
print("f4 함수 호출 결과: ${result2}");
}
Share article