Nullable First element from IEnumerable - CSharp System.Collections.Generic

CSharp examples for System.Collections.Generic:IEnumerable

Description

Nullable First element from IEnumerable

Demo Code


using System.Linq;
using System.Collections.Generic;
using System;/*w  w w .  j  a v  a 2  s . c o  m*/

public class Main{
        public static T? NullableFirst<T>(this IEnumerable<T> sequence) where T : struct {
            return sequence.Select(e => (T?)e).FirstOrDefault();
        }
}

Related Tutorials