I'm wondering if there is a way to access the different methods in the objects that I have in the code below?
using System;
using System.Windows.Forms;
namespace WindowsFormsApplication8
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
_test[0] = new TallGuy() {Height = 74, Name = "Teddy Long"};
_test[1] = new TallGuy() {Height = 64, Name = "Teddy Shorter"};
_test[2] = new TallGuy() {Height = 54, Name = "Teddy Shortest"};
}
private readonly object[] _test = new object[3];
private void button1_Click(object sender, EventArgs e)
{
for (int i = 0; i < _test.Length; i++)
{
//_test[i]. I can't call any methods here...
}
}
}
}
The reason behind me using the Object type instead of an array of one class is because I want to store different types of objects in an array. Midway through my testing though I noticed that I was unable to access the methods of the objects I had already stored in the array, hence why there is only one type of object in there.