注解

ArraySegment<T> 是一种数组的包装器，该数组分隔数组中的一系列元素。ArraySegment<T> is a wrapper around an array that delimits a range of elements in that array.多个 ArraySegment<T> 实例可以引用同一个原始数组，并且可以重叠。Multiple ArraySegment<T> instances can refer to the same original array and can overlap.原始数组必须是一维的，并且必须具有从零开始的索引。The original array must be one-dimensional and must have zero-based indexing.

每当在不同段中操作数组的元素时，ArraySegment<T> 结构都非常有用。The ArraySegment<T> structure is useful whenever the elements of an array will be manipulated in distinct segments.例如：For example:

可以将只表示数组一部分的 ArraySegment<T> 对象作为参数传递给方法，而不是调用相对开销较高的方法（如 Copy）以传递数组部分的副本。You can pass an ArraySegment<T> object that represents only a portion of an array as an argument to a method, rather than call a relatively expensive method like Copy to pass a copy of a portion of an array.

在多线程应用程序中，可以使用 ArraySegment<T> 结构使每个线程仅在数组的一个部分上操作。In a multithreaded app, you can use the ArraySegment<T> structure to have each thread operate on only a portion of the array.

对于基于任务的异步操作，可以使用 ArraySegment<T> 对象来确保每个任务在数组的不同分段上运行。For task-based asynchronous operations, you can use an ArraySegment<T> object to ensure that each task operates on a distinct segment of the array.下面的示例将一个数组分成多个包含十个元素的单独段。The following example divides an array into individual segments with up to ten elements.该段中的每个元素都乘以其段数。Each element in the segment is multiplied by its segment number.结果显示，使用 ArraySegment<T> 类以这种方式操作元素将更改其基础数组的值。The result shows that using the ArraySegment<T> class to manipulate elements in this way changes the values of its underlying array.

但请注意，尽管 ArraySegment<T> 结构可用于将一个数组划分为不同的段，但这些段并不完全相互独立。Note, however, that although the ArraySegment<T> structure can be used to divide an array into distinct segments, the segments are not completely independent of one another.Array 属性返回整个原始数组，而不是数组的副本;因此，对 Array 属性返回的数组所做的更改将对原始数组进行。The Array property returns the entire original array, not a copy of the array; therefore, changes made to the array returned by the Array property are made to the original array.如果不需要这样做，则应在数组的副本上执行操作，而不是对表示数组部分的 ArraySegment<T> 对象执行操作。If this is undesirable, you should perform operations on a copy of the array, rather than an ArraySegment<T> object that represents a portion of the array.

对序列应用累加器函数。Applies an accumulator function over a sequence.将指定的种子值用作累加器的初始值，并使用指定的函数选择结果值。The specified seed value is used as the initial accumulator value, and the specified function is used to select the result value.

计算可以为 null 的 Decimal 值序列的平均值，这些值可通过对输入序列的每个元素调用转换函数获得。Computes the average of a sequence of nullable Decimal values that are obtained by invoking a transform function on each element of the input sequence.

计算可以为 null 的 Double 值序列的平均值，这些值可通过对输入序列的每个元素调用转换函数获得。Computes the average of a sequence of nullable Double values that are obtained by invoking a transform function on each element of the input sequence.

计算可以为 null 的 Int32 值序列的平均值，这些值可通过对输入序列的每个元素调用转换函数获得。Computes the average of a sequence of nullable Int32 values that are obtained by invoking a transform function on each element of the input sequence.

计算可以为 null 的 Int64 值序列的平均值，这些值可通过对输入序列的每个元素调用转换函数获得。Computes the average of a sequence of nullable Int64 values that are obtained by invoking a transform function on each element of the input sequence.

计算可以为 null 的 Single 值序列的平均值，这些值可通过对输入序列的每个元素调用转换函数获得。Computes the average of a sequence of nullable Single values that are obtained by invoking a transform function on each element of the input sequence.

根据键选择器函数对序列中的元素进行分组。Groups the elements of a sequence according to a key selector function.通过使用比较器对键进行比较，并且通过使用指定的函数对每个组的元素进行投影。The keys are compared by using a comparer and each group's elements are projected by using a specified function.

根据指定的键选择器函数对序列中的元素进行分组，并且从每个组及其键中创建结果值。Groups the elements of a sequence according to a specified key selector function and creates a result value from each group and its key.通过使用指定的比较器对键进行比较。The keys are compared by using a specified comparer.

根据指定的键选择器函数对序列中的元素进行分组，并且从每个组及其键中创建结果值。Groups the elements of a sequence according to a specified key selector function and creates a result value from each group and its key.通过使用指定的函数对每个组的元素进行投影。The elements of each group are projected by using a specified function.

根据指定的键选择器函数对序列中的元素进行分组，并且从每个组及其键中创建结果值。Groups the elements of a sequence according to a specified key selector function and creates a result value from each group and its key.通过使用指定的比较器对键值进行比较，并且通过使用指定的函数对每个组的元素进行投影。Key values are compared by using a specified comparer, and the elements of each group are projected by using a specified function.

基于键值等同性对两个序列的元素进行关联，并对结果进行分组。Correlates the elements of two sequences based on key equality and groups the results.使用指定的 IEqualityComparer<T> 对键进行比较。A specified IEqualityComparer<T> is used to compare keys.

将序列的每个元素投影到 IEnumerable<T> 并将结果序列合并为一个序列。Projects each element of a sequence to an IEnumerable<T>, and flattens the resulting sequences into one sequence.每个源元素的索引用于该元素的投影表。The index of each source element is used in the projected form of that element.

将序列的每个元素投影到 IEnumerable<T>，并将结果序列合并为一个序列，并对其中每个元素调用结果选择器函数。Projects each element of a sequence to an IEnumerable<T>, flattens the resulting sequences into one sequence, and invokes a result selector function on each element therein.

将序列的每个元素投影到 IEnumerable<T>，并将结果序列合并为一个序列，并对其中每个元素调用结果选择器函数。Projects each element of a sequence to an IEnumerable<T>, flattens the resulting sequences into one sequence, and invokes a result selector function on each element therein.每个源元素的索引用于该元素的中间投影表。The index of each source element is used in the intermediate projected form of that element.

返回序列中的唯一元素；如果该序列为空，则返回默认值；如果该序列包含多个元素，此方法将引发异常。Returns the only element of a sequence, or a default value if the sequence is empty; this method throws an exception if there is more than one element in the sequence.

返回序列中满足指定条件的唯一元素；如果这类元素不存在，则返回默认值；如果有多个元素满足该条件，此方法将引发异常。Returns the only element of a sequence that satisfies a specified condition or a default value if no such element exists; this method throws an exception if more than one element satisfies the condition.

如果指定的条件为 true，则跳过序列中的元素，然后返回剩余的元素。Bypasses elements in a sequence as long as a specified condition is true and then returns the remaining elements.将在谓词函数的逻辑中使用元素的索引。The element's index is used in the logic of the predicate function.

计算可以为 null 的 Decimal 值序列的总和，这些值可通过对输入序列的每个元素调用转换函数获得。Computes the sum of the sequence of nullable Decimal values that are obtained by invoking a transform function on each element of the input sequence.

返回经过筛选的元素集合，其中包含源集合中每个节点的上级。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.

返回经过筛选的元素集合，其中包含源集合中每个元素和文档的子代元素。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.

返回源集合中经过筛选的每个元素和文档的子元素集合。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.