View Problem
Fetch the last element of a list
Given the list
Submit a new solution for cpp or csharp
There are 27 other solutions in additional languages (clojure, erlang, fantom, fsharp ...)
[Red, Green, Blue], access the last element ('Blue')
csharp .NET 3.5 & C# 3.0
// Make sure you import the System.Linq namespace.
// This is not the preferred way of finding the last element if you are using Lists.
string[] items = new string[] { "Red", "Green", "Blue" };
IEnumerable<string> list = new List<string>(items);
string last = list.Last(); // "Blue"
// This is not the preferred way of finding the last element if you are using Lists.
string[] items = new string[] { "Red", "Green", "Blue" };
IEnumerable<string> list = new List<string>(items);
string last = list.Last(); // "Blue"
Submit a new solution for cpp or csharp
There are 27 other solutions in additional languages (clojure, erlang, fantom, fsharp ...)




