How to convert int array into a dictionary with key and value in VB.NET

1 Answer

0 votes
Imports System
Imports System.Linq

Public Class Program
	Public Shared Sub Main(ByVal args As String())
        Dim arr As Integer() = {1, 2, 3, 4, 5, 6}

    	Dim result = From n In arr.ToDictionary(Function(k) k, Function(v) If((v Mod 2) = 1, "Odd", "Even"))
                 		Select n

    	For Each dic In result
			Console.WriteLine("{0} is {1}", dic.Key, dic.Value)
    	Next
    End Sub
End Class









' run:
'
' 1 is Odd
' 2 is Even
' 3 is Odd
' 4 is Even
' 5 is Odd
' 6 is Even
'

 



answered Dec 28, 2022 by avibootz

Related questions

1 answer 101 views
2 answers 140 views
1 answer 90 views
2 answers 212 views
1 answer 167 views
2 answers 110 views
...