You can cast one of the items in the array to bar
and as access it that way,
bar barVar = (bar)fooArray[2];
int fooBarInt = barVar.fooBar;
Or use the as
operator to treat the object as type bar
,
bar barVar = fooArray[2] as bar;
if (barVar != null)
{
// user barVar.fooBar;
}
However, the way it is define in your example fooBar
is private
. You would have to make it public
to access it outside of the class.
public class bar : foo
{
public int fooBar = 0;
}