Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / C#

System.Collections.Generic.IEnumerable: practical reference

System.Collections.Generic.IEnumerable: practical reference: IEnumerable<T> describes a sequence without promising its size, indexing, buffering, or repeatability.

Version: .NET API; verified on .NET 10.0.14

Syntax

System.Collections.Generic.IEnumerable /* select a documented member or constructor */

IEnumerable describes a sequence without promising its size, indexing, buffering, or repeatability.

Use it as the smallest read contract for consuming successive elements.

Enumerating again may repeat expensive work, produce different data, or be unsupported by a single-use source.

A source may be empty, infinite, or single-use, and failures often appear only when MoveNext executes.

The complete program actually uses System.Collections.Generic.IEnumerable; its exact expected stdout is 5.

Examples

using System;
using System.Buffers;
using System.Collections.Concurrent;
using System.Collections.Frozen;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
using System.Text.Json;
using System.Text.Json.Nodes;
using System.Text.Json.Serialization;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Channels;
using System.Threading.Tasks;
using Number = System.Int32;

IEnumerable<int> values = new[] { 2, 3 };
Console.WriteLine(values.Sum());

Result

5

The complete program actually uses `System.Collections.Generic.IEnumerable`; its exact expected stdout is `5`.

Sources