IGrouping<TKey,TElement> IGrouping<TKey,TElement> IGrouping<TKey,TElement> IGrouping<TKey,TElement> Interface

定义

表示具有公共键的对象的集合。Represents a collection of objects that have a common key.

generic <typename TKey, typename TElement>
public interface class IGrouping : System::Collections::Generic::IEnumerable<TElement>
public interface IGrouping<out TKey,out TElement> : System.Collections.Generic.IEnumerable<out TElement>
type IGrouping<'Key, 'Element> = interface
    interface seq<'Element>
    interface IEnumerable
Public Interface IGrouping(Of Out TKey, Out TElement)
Implements IEnumerable(Of Out TElement)

类型参数

TKey

IGrouping<TKey,TElement> 的键的类型。The type of the key of the IGrouping<TKey,TElement>.

TElement

IGrouping<TKey,TElement> 的值的类型。The type of the values in the IGrouping<TKey,TElement>.

实现

示例

下面的示例演示如何使用IGrouping<TKey,TElement>对象。The following example demonstrates how to work with an IGrouping<TKey,TElement> object.

在此示例中GroupBy<TSource,TKey>(IEnumerable<TSource>, Func<TSource,TKey>) ,在返回GetMembersMemberInfo对象数组上调用。In this example, GroupBy<TSource,TKey>(IEnumerable<TSource>, Func<TSource,TKey>) is called on the array of MemberInfo objects returned by GetMembers. GroupBy<TSource,TKey>(IEnumerable<TSource>, Func<TSource,TKey>)根据对象的MemberType属性值对这些对象进行分组。GroupBy<TSource,TKey>(IEnumerable<TSource>, Func<TSource,TKey>) groups the objects based on the value of their MemberType property. MemberType IGrouping<TKey,TElement> MemberInfo IGrouping<TKey,TElement>对象数组中的每个唯一值都成为新对象的键,具有该键的对象将形成对象的值序列。 MemberInfoEach unique value for MemberType in the array of MemberInfo objects becomes a key for a new IGrouping<TKey,TElement> object, and the MemberInfo objects that have that key form the IGrouping<TKey,TElement> object's sequence of values.

最后, FirstIGrouping<TKey,TElement>对象序列调用方法以仅获取第一个IGrouping<TKey,TElement>对象。Finally, the First method is called on the sequence of IGrouping<TKey,TElement> objects to obtain just the first IGrouping<TKey,TElement> object.

然后,该示例输出对象的键IGrouping<TKey,TElement> NameIGrouping<TKey,TElement>对象的值序列中每个值的属性。The example then outputs the key of the IGrouping<TKey,TElement> object and the Name property of each value in the IGrouping<TKey,TElement> object's sequence of values. 请注意,若要IGrouping<TKey,TElement>访问对象的值序列,只需IGrouping<TKey,TElement>使用变量本身。Notice that to access an IGrouping<TKey,TElement> object's sequence of values, you simply use the IGrouping<TKey,TElement> variable itself.

// Get an IGrouping object.
IGrouping<System.Reflection.MemberTypes, System.Reflection.MemberInfo> group =
    typeof(String).GetMembers().
    GroupBy(member => member.MemberType).
    First();

// Output the key of the IGrouping, then iterate
// through each value in the sequence of values
// of the IGrouping and output its Name property.
Console.WriteLine("\nValues that have the key '{0}':", group.Key);
foreach (System.Reflection.MemberInfo mi in group)
    Console.WriteLine(mi.Name);

// The output is similar to:

// Values that have the key 'Method':
// get_Chars
// get_Length
// IndexOf
// IndexOfAny
// LastIndexOf
// LastIndexOfAny
// Insert
// Replace
// Replace
// Remove
// Join
// Join
// Equals
// Equals
// Equals
// ...

' Get an IGrouping object.
Dim group As IGrouping(Of System.Reflection.MemberTypes, System.Reflection.MemberInfo) = _
    Type.GetType("String").GetMembers(). _
    GroupBy(Function(ByVal member) member.MemberType). _
    First()

' Output the key of the IGrouping, then iterate
' through each value in the sequence of values
' of the IGrouping and output its Name property.
MsgBox(String.Format("\nValues that have the key '{0}':", group.Key))
For Each mi As System.Reflection.MemberInfo In group
    MsgBox(mi.Name)
Next

' The output is similar to:

' Values that have the key 'Method':
' get_Chars
' get_Length
' IndexOf
' IndexOfAny
' LastIndexOf
' LastIndexOfAny
' Insert
' Replace
' Replace
' Remove
' Join
' Join
' Equals
' Equals
' Equals
' ...

注解

IGrouping<TKey,TElement> 为,IEnumerable<T>此外还有一个键。An IGrouping<TKey,TElement> is an IEnumerable<T> that additionally has a key. 键表示对中IGrouping<TKey,TElement>的每个值都通用的属性。The key represents the attribute that is common to each value in the IGrouping<TKey,TElement>.

在访问的元素IGrouping<TKey,TElement> IEnumerable<T>时,访问的值很多。The values of an IGrouping<TKey,TElement> are accessed much as the elements of an IEnumerable<T> are accessed. 例如foreach ,可以通过在 Visual C#或For Each Visual Basic 循环中使用来访问这些值,以便循环访问IGrouping<TKey,TElement>对象。For example, you can access the values by using a foreach in Visual C# or For Each in Visual Basic loop to iterate through the IGrouping<TKey,TElement> object. "示例" 部分包含的代码示例演示如何访问IGrouping<TKey,TElement>对象的键和值。The Example section contains a code example that shows you how to access both the key and the values of an IGrouping<TKey,TElement> object.

类型由标准查询运算符方法使用,该方法返回类型IGrouping<TKey,TElement>的元素的序列。 GroupBy IGrouping<TKey,TElement>The IGrouping<TKey,TElement> type is used by the GroupBy standard query operator methods, which return a sequence of elements of type IGrouping<TKey,TElement>.

属性

Key Key Key Key

获取 IGrouping<TKey,TElement> 的键。Gets the key of the IGrouping<TKey,TElement>.

方法

GetEnumerator() GetEnumerator() GetEnumerator() GetEnumerator()

返回循环访问集合的枚举数。Returns an enumerator that iterates through a collection.

(Inherited from IEnumerable)

扩展方法

CopyToDataTable<T>(IEnumerable<T>) CopyToDataTable<T>(IEnumerable<T>) CopyToDataTable<T>(IEnumerable<T>) CopyToDataTable<T>(IEnumerable<T>)

在给定其泛型参数 TDataTable 的输入 DataRow 对象的情况下,返回包含 IEnumerable<T> 对象副本的 DataRowReturns a DataTable that contains copies of the DataRow objects, given an input IEnumerable<T> object where the generic parameter T is DataRow.

CopyToDataTable<T>(IEnumerable<T>, DataTable, LoadOption) CopyToDataTable<T>(IEnumerable<T>, DataTable, LoadOption) CopyToDataTable<T>(IEnumerable<T>, DataTable, LoadOption) CopyToDataTable<T>(IEnumerable<T>, DataTable, LoadOption)

在给定其泛型参数 TDataRow 的输入 DataTable 对象的情况下,将 IEnumerable<T> 对象复制到指定的 DataRowCopies DataRow objects to the specified DataTable, given an input IEnumerable<T> object where the generic parameter T is DataRow.

CopyToDataTable<T>(IEnumerable<T>, DataTable, LoadOption, FillErrorEventHandler) CopyToDataTable<T>(IEnumerable<T>, DataTable, LoadOption, FillErrorEventHandler) CopyToDataTable<T>(IEnumerable<T>, DataTable, LoadOption, FillErrorEventHandler) CopyToDataTable<T>(IEnumerable<T>, DataTable, LoadOption, FillErrorEventHandler)

在给定其泛型参数 TDataRow 的输入 DataTable 对象的情况下,将 IEnumerable<T> 对象复制到指定的 DataRowCopies DataRow objects to the specified DataTable, given an input IEnumerable<T> object where the generic parameter T is DataRow.

Cast<TResult>(IEnumerable) Cast<TResult>(IEnumerable) Cast<TResult>(IEnumerable) Cast<TResult>(IEnumerable)

IEnumerable 的元素强制转换为指定的类型。Casts the elements of an IEnumerable to the specified type.

OfType<TResult>(IEnumerable) OfType<TResult>(IEnumerable) OfType<TResult>(IEnumerable) OfType<TResult>(IEnumerable)

根据指定类型筛选 IEnumerable 的元素。Filters the elements of an IEnumerable based on a specified type.

AsParallel(IEnumerable) AsParallel(IEnumerable) AsParallel(IEnumerable) AsParallel(IEnumerable)

启用查询的并行化。Enables parallelization of a query.

AsQueryable(IEnumerable) AsQueryable(IEnumerable) AsQueryable(IEnumerable) AsQueryable(IEnumerable)

IEnumerable 转换为 IQueryableConverts an IEnumerable to an IQueryable.

Ancestors<T>(IEnumerable<T>) Ancestors<T>(IEnumerable<T>) Ancestors<T>(IEnumerable<T>) Ancestors<T>(IEnumerable<T>)

返回元素集合,其中包含源集合中每个节点的上级。Returns a collection of elements that contains the ancestors of every node in the source collection.

Ancestors<T>(IEnumerable<T>, XName) Ancestors<T>(IEnumerable<T>, XName) Ancestors<T>(IEnumerable<T>, XName) Ancestors<T>(IEnumerable<T>, XName)

返回经过筛选的元素集合,其中包含源集合中每个节点的上级。Returns a filtered collection of elements that contains the ancestors of every node in the source collection. 集合中仅包括具有匹配 XName 的元素。Only elements that have a matching XName are included in the collection.

DescendantNodes<T>(IEnumerable<T>) DescendantNodes<T>(IEnumerable<T>) DescendantNodes<T>(IEnumerable<T>) DescendantNodes<T>(IEnumerable<T>)

返回源集合中每个文档和元素的子代节点的集合。Returns a collection of the descendant nodes of every document and element in the source collection.

Descendants<T>(IEnumerable<T>) Descendants<T>(IEnumerable<T>) Descendants<T>(IEnumerable<T>) Descendants<T>(IEnumerable<T>)

返回元素集合,其中包含源集合中每个元素和文档的子代元素。Returns a collection of elements that contains the descendant elements of every element and document in the source collection.

Descendants<T>(IEnumerable<T>, XName) Descendants<T>(IEnumerable<T>, XName) Descendants<T>(IEnumerable<T>, XName) Descendants<T>(IEnumerable<T>, XName)

返回经过筛选的元素集合,其中包含源集合中每个元素和文档的子代元素。Returns a filtered collection of elements that contains the descendant elements of every element and document in the source collection. 集合中仅包括具有匹配 XName 的元素。Only elements that have a matching XName are included in the collection.

Elements<T>(IEnumerable<T>) Elements<T>(IEnumerable<T>) Elements<T>(IEnumerable<T>) Elements<T>(IEnumerable<T>)

返回源集合中每个元素和文档的子元素的集合。Returns a collection of the child elements of every element and document in the source collection.

Elements<T>(IEnumerable<T>, XName) Elements<T>(IEnumerable<T>, XName) Elements<T>(IEnumerable<T>, XName) Elements<T>(IEnumerable<T>, XName)

返回源集合中经过筛选的每个元素和文档的子元素集合。Returns a filtered collection of the child elements of every element and document in the source collection. 集合中仅包括具有匹配 XName 的元素。Only elements that have a matching XName are included in the collection.

InDocumentOrder<T>(IEnumerable<T>) InDocumentOrder<T>(IEnumerable<T>) InDocumentOrder<T>(IEnumerable<T>) InDocumentOrder<T>(IEnumerable<T>)

返回节点集合(其中包含源集合中的所有节点),并按文档顺序排列。Returns a collection of nodes that contains all nodes in the source collection, sorted in document order.

Nodes<T>(IEnumerable<T>) Nodes<T>(IEnumerable<T>) Nodes<T>(IEnumerable<T>) Nodes<T>(IEnumerable<T>)

返回源集合中每个文档和元素的子节点集合。Returns a collection of the child nodes of every document and element in the source collection.

Remove<T>(IEnumerable<T>) Remove<T>(IEnumerable<T>) Remove<T>(IEnumerable<T>) Remove<T>(IEnumerable<T>)

将源集合中的每个节点从其父节点中移除。Removes every node in the source collection from its parent node.

适用于