fork(1) download
  1. Imports System
  2. Imports System.Collections.Generic
  3.  
  4. Public Class Test
  5. Public Shared Sub Main()
  6. Dim list_target As New List(Of Integer)(New Integer() {1, 2, 5, 5, 7, 8, 9, 10, 10, 12})
  7.  
  8. Dim _tmp As New List(Of Integer)
  9. For Each obj As Integer In list_target
  10. If obj Mod 2 = 0 Then
  11. ' 要刪除的部分
  12. Else
  13. ' 要留下來的部分
  14. _tmp.Add(obj)
  15. End If
  16. Next
  17. list_target = _tmp
  18.  
  19. ' 相當於下面: (VB 2010
  20. 'Dim list_target As New List(Of Integer)({1, 2, 5, 5, 7, 8, 9, 10, 10, 12})
  21. 'list_target = list_target.FindAll(
  22. ' Function(obj As Integer) As Boolean
  23. ' If obj Mod 2 = 0 Then
  24. ' Return False ' 要刪除的部分
  25. ' Else
  26. ' Return True
  27. ' End If
  28. ' End Function
  29. ')
  30.  
  31. For Each obj As Integer In list_target
  32. Console.WriteLine(obj)
  33. Next
  34. End Sub
  35. End Class
Success #stdin #stdout 0.07s 13488KB
stdin
Standard input is empty
stdout
1
5
5
7
9