Wednesday, January 30, 2013

C# List TakeFirst()


        ///     Remove and return the first item in the list, otherwise return null.
        public static TType TakeFirst( this IList list ) {
            if ( list == null ) {
                throw new ArgumentNullException( "list" );
            }
            if ( list.Count <= 0 ) {
                return default( TType );
            }
            var item = list[ 0 ];
            list.RemoveAt( 0 );
            return item;
        }

No comments: