Extract Specific Subset from Array - CSharp System

CSharp examples for System:Array Operation

Description

Extract Specific Subset from Array

Demo Code


using System.Text;
using System.Collections;
using System;/*from   w  w  w .  j  a  v a  2  s. c o m*/

public class Main{
        // create a subset from a specific list of indices
        public static T[] ExtractSpecificSubset<T>(this T[] array, params int[] indices)
        {
            T[] subset = new T[indices.Length];
            for (int i = 0; i < indices.Length; i++)
            {
                subset[i] = array[indices[i]];
            }
            return subset;
        }
}

Related Tutorials