Helper method which turns a single item into an enumerable. - CSharp System.Collections.Generic

CSharp examples for System.Collections.Generic:IEnumerable

Description

Helper method which turns a single item into an enumerable.

Demo Code


using System.Linq;
using System;/* w ww .j  av a2  s  .c  o  m*/
using System.Collections.Generic;
using System.Collections;
using UnityEngine;

public class Main{
        /// <summary>
        /// Helper method which turns a single item into an enumerable. 
        /// </summary>
        public static IEnumerable<T> ToEnumerable<T>(this T item)
        {
            if (item == null)
                yield break;

            yield return item;
        }
}

Related Tutorials