Logo

Programming-Idioms

History of Idiom 165 > diff from v49 to v50

Edit summary for version 50 by Kit Grose:
[Csharp] Add required import.

Version 49

2019-09-27, 02:42:50

Version 50

2019-09-27, 02:54:02

Idiom #165 Last element of list

Assign to variable x the last element of list items.

Idiom #165 Last element of list

Assign to variable x the last element of list items.

Imports
Imports
using System.Linq;
Code
var x = items.LastOrDefault();
Code
var x = items.LastOrDefault();
Comments bubble
Returns the default value for the type of x if items is empty. Use items.Last() if you would prefer an exception.