LastOrDefault method (with objects)

Description

The LastOrDefault method returns the last element of a sequence, or a default value if the sequence contains no elements.

Sample

This sample gets the last element of a collection or the deault value, if the collection is empty.

var data := List<int>{}

var result := data:LastOrDefault()

Console.WriteLine(result)

Output

0

Complete sample

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

procedure Execute() as void strict

   var data := List<int>{}

   var result := data:LastOrDefault()

   Console.WriteLine(result)
   return