I want to upcast object array to different array of different object type like below
object[] objects; // assuming that it is non-empty
CLassA[] newObjects = obj
As this post suggests, you may be able to do the following trick (untested):
newObjects = (ClassA[])(object)objects;
Note that in C# 4.0 you won't need to cast, you will be able to directly assign newObjects = objects
.
using System.Linq;
newObjects = objects.Select(eachObject => (ClassA)eachObject).ToArray();
Or I guess you could try something like this for even shorter syntax:
newObjects = objects.Cast<ClassA>().ToArray();