Calculate sum with unlimited number of arguments | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Calculate sum with unlimited number of arguments

Did you know you can use a unlimited number of arguments in a method definition. We are use to this when we see static void Main(string[] args) I did not expect that I could use it myself, with the params keyword we can static int sum(params int[] args){} for example : int ResultOffThree = sum(10,20,30); int ResultOffFive = sum(10,20,30,40,50); I came across this reading a textbook and wanted to share it with you. https://code.sololearn.com/caCi0bohxL2l

20th Sep 2017, 9:27 PM
sneeze
sneeze - avatar
2 Answers
+ 10
Thx, nice to share your knowledge! (In Java it is 'public int sum(Integer.. i)' and the elements can be accessed the array-way) https://code.sololearn.com/c0Bf2pqc6ww1/?ref=app
20th Sep 2017, 9:36 PM
Tashi N
Tashi N - avatar
+ 1
You can actually use it in public static void Main(string... args)
20th Sep 2017, 10:05 PM
Joefrey Racal Ramos
Joefrey Racal Ramos - avatar