Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Implementing Arrays 1

Status
Not open for further replies.

werjocks

Programmer
Oct 27, 2003
24
US
Hi,
I'm a new C# programmer trying to figure out how to implement arrays of instances for classes I generate... I tried something that barfed like this:

bar [] foo;

public void initializefoo(){
for(int i=0; i<5; i++)
{
foo = new bar();
}
}

I understand I might have to implement the System.Array class... does anyone have an example of what I need to do?
 
You can also use an ArrayList (using System.Collections).

ArrayList myArray = new ArrayList;

myArray.Add(<yourclass>);



The only downfall is that you have to cast the object back to your class later.

bar myBar = (bar)myArray[0];

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top