Converting arrays

a friend asked me this: how do I convert one type of array to another when the cast between the items is valid? I did this before but still it took me 15 min. to find how to do it. so here is a reminder for me.

here is a sample where Son is derived from Father:

Father[] f = new Father[] {new Son(2,1), new Son(3,2) };

System.Collections.ArrayList a = new System.Collections.ArrayList(f);

Son[] s = (Son[])a.ToArray(typeof(Son));

Comments (0)

Skip to main content