Mega Code Archive

 
Categories / VB.Net / LINQ
 

Using Select to produce a sequence of new objects from two arrays with calculation

Imports System.IO Imports System.Reflection Imports System.Linq Imports System.Xml.Linq Public Class MainClass    Public Shared Sub Main         Dim numbers As Integer() = {5, 4, 1, 3, 9, 8, 6, 7, 2, 0}         Dim stringNames As String() = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"}         Dim digitOddEvens = From num In numbers _                             Select Digit = stringNames(num), Even = ((num Mod 2) = 0)         For Each d In digitOddEvens             Console.WriteLine("The digit " & d.Digit & " is " & If(d.Even, "even", "odd"))         Next    End Sub End Class