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__2y 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
More Posts
❔ How do I pull information out of a function with alot of information?**I'm getting an error in the below statement SPECIFICALLY at keySet with the error "the name 'keySe❔ Single UDP Broadcaster to Multiple ClientsI'm trying to have a single UDP Broadcast to many clients. This is what I have working so far. Idea❔ how to logout specific user with identityserverI am trying to logout an specific user from previous identity user sessions, so what could I do to ❔ The type 'Attribute' is defined in an assembly that is not referenced.On a dotnet 7 xunit template, I added specflow and the title error pops upHow do I create a class with an array within it?I'm trying to create a class for people with an array of hobbies within it, but cannot figure out ho❔ EF Core - Select items such that attribute sum is greater than...Hi everyone, I have an object Recording having attributes start_time and size_byte. Now, when the s❔ alternative to switch statement or if statements?is there something better I can use in this situation? ```cs int size = 300; switch (HLevel.CurrentL❔ deserialize json object which should be an arrayHi, how can i deserialize a json-string like this, if i dont know how many "items" (item0, item1, itCan Free Visual studio community work for 1 web developer? [Answered]I would like to know, given that visual studio would be use only by me, 1 web developer so it's not ❔ Returning an async dictionary ?I am calling this function from an api endpoint and want to return the results from the tasks. Right