Skip to content

Instantly share code, notes, and snippets.

@zoren
Last active December 14, 2015 16:39
Show Gist options
  • Save zoren/5116859 to your computer and use it in GitHub Desktop.
Save zoren/5116859 to your computer and use it in GitHub Desktop.
private static Array DownCastArray<TE>( TE[] ar, Type elementType ) {
Array castDown = Array.CreateInstance( elementType, ar.Length );
for ( int i = 0; i < ar.Length; i++ ) {
object value = ar[i];
if ( !elementType.IsInstanceOfType( value ) ) {
throw new ArgumentException( "df" );
}
castDown.SetValue( value, i );
}
return castDown;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment