Created
April 22, 2018 22:01
-
-
Save ivanxpetrov/4667dad036e1d8c8ea143f46e20725b4 to your computer and use it in GitHub Desktop.
Revisions
-
Ivan Petrov created this gist
Apr 22, 2018 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,34 @@ void Main() { var list0 = new List<int>(); var list1 = new List<int>() { 1 }; var list2 = new List<int> { 0,1,-2 }; Sum(list0).Dump($"{list0.Stringify()}"); Sum(list1).Dump($"{list1.Stringify()}"); Sum(list2).Dump($"{list2.Stringify()}"); } int Sum(IList<int> listNumbers, int startIndex = 0) { if (startIndex == listNumbers.Count) { return 0; } if (startIndex == listNumbers.Count - 1) { return listNumbers[startIndex]; } return listNumbers[startIndex] + Sum(listNumbers, startIndex + 1); }