Filter Dictionary with OfType in CSharp
Description
The following code shows how to filter Dictionary with OfType.
Example
//from w w w . j a v a2 s.c o m
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
public class MainClass{
public static void Main(string[] args){
Dictionary<String, Object> TestData = new Dictionary<string, object>();
TestData.Add("One", 1);
TestData.Add("Two", "Two");
TestData.Add("Three", 3);
TestData.Add("Four", "Four");
TestData.Add("Five", 5);
TestData.Add("Six", "Six");
var ThisQuery = TestData.Values.OfType<String>();
foreach (String ThisElement in ThisQuery)
Console.WriteLine(ThisElement);
}
}
The code above generates the following result.