Collection To Array - CSharp System

CSharp examples for System:Array Element

Description

Collection To Array

Demo Code

// Copyright (c) .NET Foundation. All rights reserved.
using System.Diagnostics;
using System.Collections.Generic;
using System.Collections;
using System;/*from w  w  w  .  j  a  v a 2  s .c om*/

public class Main{
        public static Array CollectionToArray(ICollection collection, Type elementType)
        {
            Array newArray = Array.CreateInstance(elementType, collection.Count);
            collection.CopyTo(newArray, 0);
            return newArray;
        }
}

Related Tutorials