chamsi09

Untitled

Nov 14th, 2024
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 0.51 KB | None | 0 0
  1. Function SumListRecursive(numbers As List(Of Integer)) As Integer
  2.         ' Base case: if the list is empty, return 0
  3.         If numbers.Count = 0 Then
  4.             Return 0
  5.         Else
  6.             ' Recursive case: add the first element to the sum of the rest of the list
  7.             Dim firstElement As Integer = numbers(0)
  8.             Dim remainingElements As List(Of Integer) = numbers.Skip(1).ToList()
  9.             Return firstElement + SumListRecursive(remainingElements)
  10.         End If
  11.     End Function
Advertisement
Add Comment
Please, Sign In to add comment