C
C#2y ago
bialasik__

What is the difference between these two methods? Using params or just doing everything in one class

public static void Main(string[] args) {
int a = 2, b = 3;
int sum = Add(a, b)
}

public static int Add(int a, int b) {
return a + b;
}
//5 variables
public static void Main(string[] args) {
int a = 2, b = 3;
int sum = Add(a, b)
}

public static int Add(int a, int b) {
return a + b;
}
//5 variables
public static void Main(string[] args) {
int a = 2, b = 3;
int sum = a + b;
}
//3 variables
public static void Main(string[] args) {
int a = 2, b = 3;
int sum = a + b;
}
//3 variables
i just learned this in class and dont get why this is a thing
4 Replies
Angius
Angius2y ago
Having a separate method allows you to reuse it It's not as visible with just doing addition inside, but if you were doing some more complex operations, it's very useful
bialasik__
bialasik__OP2y ago
makes sense ty
trunksvn
trunksvn2y ago
we usually only create a method, when you know you'll need to use the code again
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server