Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / C#

^: practical reference

^: practical reference: ^ creates an Index measured from the end, where ^1 denotes the last element.

Version: C# language; verified against C# 14 reference

Syntax

^expression

^ creates an Index measured from the end, where ^1 denotes the last element.

Use it with indexers or ranges for clear access relative to a sequence's end.

^0 denotes the position after the end and is not a valid element index.

An empty sequence has no ^1, and the type must support the indexing pattern.

The complete program actually uses ^; its exact expected stdout is 30.

Examples

using System;
using System.Linq;
using System.Threading.Tasks;

var values = new[] { 10, 20, 30 }; Console.WriteLine(values[^1]);

Result

30

The complete program actually uses `^`; its exact expected stdout is `30`.

Sources