public static Array array(Type elementType, ICollection collection)
{
if (null == collection)
{
throw new ArgumentNullException("collection");
}
if (null == elementType)
{
throw new ArgumentNullException("elementType");
}
Array array = Array.CreateInstance(elementType, collection.Count);
if (RuntimeServices.IsPromotableNumeric(Type.GetTypeCode(elementType)))
{
int i=0;
foreach (object item in collection)
{
object value = RuntimeServices.CheckNumericPromotion(item).ToType(elementType, null);
array.SetValue(value, i);
++i;
}
}
else
{
collection.CopyTo(array, 0);
}
return array;
}