dartpad.dev
Typedef 함수 정의
void main() {
Operation operation = add;
int result = operation (10,20,30);
print(result);
int result2 = calculate(10,20,30,add) ;
print(result2);
int result3 = calculate(10,20,30,subtract);
print(result3);
}
typedef Operation = int Function (int x, int y, int z);
int add(int x, int y, int z) => x+ y+ z;
int subtract(int x, int y , int z) => x - y - z;
int calculate(int x, int y, int z, Operation operation){
return operation(x,y,z);
}
반응형