Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!
  • C#
using System.Linq;
var x = items.LastOrDefault();

Returns the default value for the type of x if items is empty. Use items.Last() if you would prefer an exception.
var x = items[^1];

C# 8 introduced the index-from-end operator ^.
var x = items[items.Count-1];
X := Items'Last

X must be declared earlier.

New implementation...