-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.dart
51 lines (45 loc) · 1.03 KB
/
functions.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/*
1.Functions are used to increase reusability of code.
2.In dart,functions always return something,if we have not returned,then default is null.
*/
main(){
getNumber(){
print("Hello");
}
getNumber();
//parametrized functions(without storin value of function in variable)
getProduct(int a,int b){
print(a*b);
}
getProduct(3,6);
//parametrized function(by storing value of function in variable,function uses print)
getExpression(int x,int y){
print(x+y*10);
}
var e=getExpression(3,4);
print(e);
//parametrized function(by storing value of function in variable,function uses return)
getExpression2(int x,int y){
return(x+y*10);
}
var f=getExpression2(3,4);
print(f);
//FAT Arrow
getArrow(int q,int w)=>(q*w)+10;
var x=getArrow(3, 4);
print(x*2);
//optional parameters
getNum(int s,[int d=10]){
print(s*d);
}
getNum(3);
//Named parameters
getNamed(int x,{var y,var z}){
print(x);
print(y);
print(z);
var num=(x+y)*z;
print(num);
}
getNamed(10,z:30,y:20);
}