Last method (with integers)

Description

The Last method returns the first element of a sequence or throws an exception, if the sequence is empty.

Sample

This sample throws an exception, because the list is empty.

var data := List<int>{}

try
   var result := data:Last()

   Console.WriteLine(result)
catch
   Console.WriteLine("Exception was thrown, because list is empty")
end try

Output

Exception was thrown, because list is empty

Complete sample

using System
using System.Linq
using System.Collections.Generic

procedure Execute() as void strict

   var data := List<int>{}

   try
      var result := data:Last()

      Console.WriteLine(result)
   catch
      Console.WriteLine("Exception was thrown, because list is empty")
   end try
   return