Dynamic colection??

  • Thread starter Thread starter Paez
  • Start date Start date
P

Paez

Hi there.

I have a Myclass[] obj1 that I will fill with some data but I do not know
how much elements there will be. How can I declare it or resize it?

Right now, I declare Myclass[] obj1=new Myclass[100]. Later, when I need to
show all elements, I do this:

foreach (Myclass x in obj1)
{
if (x == null)
continue;
System.Console.WriteLine(x.ToString());
}

I don't thinks this is the best way.

Any help? Thanks.

Paez
 
Hi,

Use the generic System.Collections.Generic.List class in the 2.0 Framework
and the System.Collections.ArrayList class in previous framework versions.
 
"Paez" <marco.pais@[IGNORE]gmail.com> a écrit dans le message de (e-mail address removed)...

| I have a Myclass[] obj1 that I will fill with some data but I do not know
| how much elements there will be. How can I declare it or resize it?
|
| Right now, I declare Myclass[] obj1=new Myclass[100]. Later, when I need
to
| show all elements, I do this:
|
| foreach (Myclass x in obj1)
| {
| if (x == null)
| continue;
| System.Console.WriteLine(x.ToString());
| }
|
| I don't thinks this is the best way.

If you are using .NET 1.1 then ArrayList is what you need.

In .NET 2.0, use a List<MyClass> generic list.

Joanna
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top