Map value in ICollection - CSharp System.Collections

CSharp examples for System.Collections:ICollection

Description

Map value in ICollection

Demo Code

// Copyright (c) Microsoft. All rights reserved.
using System.Collections.Generic;

public class Main{
        // Name needs to be different so it doesn't conflict with Enumerable.Select
        public static U[] Map<T, U>(this ICollection<T> collection, Func<T, U> select)
        {/*from w  w  w  .  j a v  a2s.  co  m*/
            int count = collection.Count;
            U[] result = new U[count];
            count = 0;
            foreach (T t in collection)
            {
                result[count++] = select(t);
            }
            return result;
        }
}

Related Tutorials