Skip to content

Instantly share code, notes, and snippets.

@xProgrammer-007
Last active October 11, 2019 07:26
Show Gist options
  • Save xProgrammer-007/cebbe6fc30301d1c7b2e29fd8aeed1f1 to your computer and use it in GitHub Desktop.
Save xProgrammer-007/cebbe6fc30301d1c7b2e29fd8aeed1f1 to your computer and use it in GitHub Desktop.
// make a method that takes 2 numbers as its inputs . and returns the sum of those numbers .
void main() {
int result = addTwoNumbers(8765,1688);
print(result);
}
// while you create a method , these are the steps you follow
// 1: What does the method return For Eg.(int , String , double , ...)
// 2: What does the method input / takes as inputs
// 3: return
int addTwoNumbers(int a , int b){
return (a+b);
}
/// ------------------------------ Previously what i learned ----------------------------
// This is the main method , that dart uses to know the beginning of the code
void main() {
int a = 10;
String c = "Rishikesh";
double d = 25.5;
// this is how you call a function/method you defined earlier
int x = add();
int y = addAB(10,200);
print(x);
print(y);
}
//to define a ( method / function ) this is how you do it
// This is a basic method where it returns a integer data type and returns 100
int add (){
return 100;
}
//How about i want to make a method where i return a int and i also take 2 numbers as inputs and calculate the addition
int addAB(int a , int b){
return a + b;
}
// ------ classes declaring and making objects ------
// a company wants me to create a game where a car, car should have its name , its topspeed and its wheelname
void main() {
Car maruti = new Car();
maruti.name = "Maturi 800";
maruti.topSpeed = 130;
maruti.wheelName = "MRF TIRES";
print(maruti.name);
print(maruti.topSpeed);
print(maruti.wheelName);
}
// A class is basically a blue print of any entity.
class Car{
String name;
int topSpeed;
String wheelName;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment