I have an overridden method that has an object parameter. I am determining if this is an array, and then want to determine its length:
public override bool IsValid(object value)
{
Type type = value.GetType();
if (type.IsArray)
{
return ((object[]) value).Length > 0;
}
else
{
return false;
}
}
The problem is if value is an int[], it errors when I try to cast to an object[]. Is there any way to handle this cast so it will work with any type of array?
object[], because all the values need to be boxed. All that aside, what you're doing seems like a code smell; are you sure you can't just accept anArrayas the parameter?valueis not an array?