Filtered: prints the name of each element of an integer array that is less than 5

image_pdfimage_print

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class MainClass {
public static void Main() {

int[] numbers = { 5, 4, 1, 3};
string[] digits = { “zero”, “one”, “two”, “three”};

var lowNums =
from n in numbers
where n < 5 select digits[n]; Console.WriteLine("Numbers < 5:"); foreach (var num in lowNums) { Console.WriteLine(num); } } } [/csharp]

This entry was posted in LINQ. Bookmark the permalink.