To Sorted Array - CSharp System

CSharp examples for System:Array Sort

Description

To Sorted Array

Demo Code


using System.Linq;
using System.Text;
using System.Globalization;
using System.ComponentModel;
using System.Collections.Generic;
using System.Collections;

public class Main{
        public static TSource[] ToSortedArray<TSource>(this System.Collections.Generic.IEnumerable<TSource> source)
            where TSource: IComparable<TSource>
        {/*from ww  w .java  2 s  . co  m*/
            var res = source.ToArray();
            Array.Sort(res);
            return res;
        }
        public static TSource[] ToSortedArray<TSource>(this System.Collections.Generic.IEnumerable<TSource> source, Comparison<TSource> comparer)
        {
            var res = source.ToArray();
            Array.Sort(res, comparer);
            return res;
        }
}

Related Tutorials