Convert to IList - CSharp System.Collections.Generic

CSharp examples for System.Collections.Generic:IList

Description

Convert to IList

Demo Code


using System.Collections;
using System.Text;
using System.Linq;
using System.Collections.Generic;
using System;/*from  ww  w.j  ava2 s  .  co  m*/

public class Main{
        public static IList<R> Yield<Key, Value, R>(this IDictionary<Key, Value> source, Func<KeyValuePair<Key, Value>, R> func)
        {
            if (source == null)
            { return new List<R>(); }

            IList<R> lstR = new List<R>();
            foreach (var item in source)
            {
                lstR.Add(func(item));
            }
            return lstR;
        }
        public static IList<R> Yield<T, R>(this IEnumerable<T> source, Func<T, R> func, Func<T, bool> condition)
        {
            if (source == null)
            { return new List<R>(); }

            IList<R> lstR = new List<R>();
            foreach (var item in source)
            {
                if (condition(item))
                {
                    lstR.Add(func(item));
                }
            }
            return lstR;
        }
        public static IList<R> Yield<T, R>(this IEnumerable<T> source, Func<T, R> func)
        {
            if (source == null)
            { return new List<R>(); }

            IList<R> lstR = new List<R>();
            foreach (var item in source)
            {
                lstR.Add(func(item));
            }
            return lstR;
        }
}

Related Tutorials