How to count specific element in list with VB.NET

1 Answer

0 votes
Imports System
Imports System.Collections.Generic

Public Class Program
	Public Shared Sub Main()
		Dim lst = New List(Of Integer)({2, 6, 1, 5, 8, 1, 1, 0, 9, 1 })
		
		Dim count As Integer = 0
		For Each item As Integer In lst
			If item = 1 Then
				count += 1
			End If
		Next
        
		Console.WriteLine(count)
			
    End Sub
End Class



' run:
'
' 4
'

 



answered Sep 5, 2023 by avibootz

Related questions

...