Lookup<TKey, TElement>.Item Property

Updated: January 2010

Gets the collection of values indexed by the specified key.

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

public IEnumerable<TElement> this[
	TKey key
] { get; }

Parameters

key
Type: TKey

The key of the desired collection of values.

Property Value

Type: System.Collections.Generic.IEnumerable<TElement>
The collection of values indexed by the specified key.

Implements

ILookup<TKey, TElement>.Item[TKey]

This indexed property provides the ability to index a specific collection of values in the Lookup<TKey, TElement> by using the following syntax: myLookup[key] in Visual C# or myLookup(key) in Visual Basic. If key is not found in the collection, an empty sequence is returned.

The following example demonstrates how to use Item to index directly into a Lookup<TKey, TElement>. This code example is part of a larger example provided for the Lookup<TKey, TElement> class.

// Select a collection of Packages by indexing directly into the Lookup.
IEnumerable<string> cgroup = lookup['C'];

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

Date

History

Reason

January 2010

Updated the "Remarks" section with information about what happens when the key is not found.

Customer feedback.

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2015 Microsoft