+ 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
2 Réponses
+ 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
+ 1
You can actually use it in public static void Main(string... args)