Scrape all of the items in the collection which are not null. - CSharp System.Collections.Generic

CSharp examples for System.Collections.Generic:ICollection

Description

Scrape all of the items in the collection which are not null.

Demo Code


using System.Linq;
using System;/*from  w w w.ja va2 s . c o m*/
using System.Collections.Generic;
using System.Collections;
using UnityEngine;

public class Main{
        /// <summary>
        /// Scrape all of the items in the collection which are not null.
        /// </summary>
        public static IEnumerable<T> ScrapeNonNullItems<T>(this IEnumerable<T> self)
            where T : class
        {
            if (self == null)
            {
                Debug.LogException(new ArgumentNullException("source"));
                yield break;
            }

            foreach (var item in self)
            {
                if (item == null)
                    continue;

                yield return item;
            }
        }
}

Related Tutorials