This documentation is archived and is not being maintained.

Lookup<TKey, TElement> Class

Represents a collection of keys each mapped to one or more values.

Namespace:  System.Linq
Assembly:  System.Core (in System.Core.dll)

generic<typename TKey, typename TElement>
public ref class Lookup : ILookup<TKey, TElement>, 
	IEnumerable<IGrouping<TKey, TElement>^>, IEnumerable

Type Parameters


The type of the keys in the Lookup<TKey, TElement>.


The type of the elements of each IEnumerable<T> value in the Lookup<TKey, TElement>.

A Lookup<TKey, TElement> resembles a Dictionary<TKey, TValue>. The difference is that a Dictionary<TKey, TValue> maps keys to single values, whereas a Lookup<TKey, TElement> maps keys to collections of values.

You can create an instance of a Lookup<TKey, TElement> by calling ToLookup on an object that implements IEnumerable<T>.


There is no public constructor to create a new instance of a Lookup<TKey, TElement>. Additionally, Lookup<TKey, TElement> objects are immutable, that is, you cannot add or remove elements or keys from a Lookup<TKey, TElement> object after it has been created.

The following example creates a Lookup<TKey, TElement> from a collection of objects. It then enumerates the Lookup<TKey, TElement> and outputs each key and each value in the key's associated collection of values. It also demonstrates how to use the properties Count and Item and the methods Contains and GetEnumerator.

No code example is currently available or this language may not be supported.

  System.Linq::Lookup<TKey, TElement>

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows CE, Windows Mobile for Smartphone, Windows Mobile for Pocket PC, Xbox 360, Zune

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5

.NET Compact Framework

Supported in: 3.5

XNA Framework

Supported in: 3.0