+ 1

C# When are we pass arguments

Sometimes in some methods we are using passing arguments but sometimes we are not we are directly using : for using arguments Why is it

25th Feb 2021, 8:49 PM
Codelearner
7 ответов
+ 1
Arguments make code reusable That means less code to write, less code to maintain By using arguments you only need to write one method instead of three And you can pass arguments you did not think off in the first place. Did this amswer your question? https://code.sololearn.com/c1a21A205A1A/?ref=app
26th Feb 2021, 5:09 PM
sneeze
sneeze - avatar
+ 1
sneeze yes why did not you use res or out at this code
26th Feb 2021, 5:17 PM
Codelearner
+ 1
In this example, I did not need to change the value of name. So pass by value was enough. Ref and Out do change the value of the argument in a method. https://code.sololearn.com/c0mzKfHb0nuM/?ref=app
26th Feb 2021, 5:36 PM
sneeze
sneeze - avatar
+ 1
sneeze //by value : The value of A can change within method, but the outside the method the value of A is not changed
27th Feb 2021, 6:59 PM
Codelearner
+ 1
sneeze i didnt understand why
27th Feb 2021, 7:00 PM
Codelearner
+ 1
thank you so much sneeze i understood
28th Feb 2021, 2:13 PM
Codelearner
0
Because some arguments are input only. public int Add(int x, int y) { return x+y; } In this method the value of x and y are important to get the return value. But once this method has finished you do not need x and y anymore. public void PrintX(int x) { Console.WriteLine(x); } The method returns nothing, the method need a input value x. But this value, is only used in the method. So it does not need to be changed and returned via a reference to the main method. General rule, try to return as less as possible
27th Feb 2021, 8:12 PM
sneeze
sneeze - avatar