PC Review


Reply
Thread Tools Rate Thread

Dynamic colection??

 
 
Paez
Guest
Posts: n/a
 
      1st Jan 2007
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


 
Reply With Quote
 
 
 
 
Dave Sexton
Guest
Posts: n/a
 
      1st Jan 2007
Hi,

Use the generic System.Collections.Generic.List class in the 2.0 Framework
and the System.Collections.ArrayList class in previous framework versions.

--
Dave Sexton
http://davesexton.com/blog

"Paez" <marco.pais@[IGNORE]gmail.com> wrote in message
news:(E-Mail Removed)...
> 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
>



 
Reply With Quote
 
Joanna Carter [TeamB]
Guest
Posts: n/a
 
      1st Jan 2007
"Paez" <marco.pais@[IGNORE]gmail.com> a écrit dans le message de news:
(E-Mail 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

--
Joanna Carter [TeamB]
Consultant Software Engineer


 
Reply With Quote
 
Paez
Guest
Posts: n/a
 
      1st Jan 2007
Thanks for the answers.

It help a lot...

Paez

"Paez" <marco.pais@[IGNORE]gmail.com> wrote in message
news:(E-Mail Removed)...
> 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
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
DVD Colection Katie Microsoft Access Getting Started 1 18th Feb 2005 12:18 AM
how to set up database containing dvd colection (borrowed,lent an. =?Utf-8?B?VHJveQ==?= Microsoft Access Database Table Design 1 23rd Jan 2005 07:32 PM
Repeater, Panel, dynamic user control - can't retrieve dynamic controls in code behind theComputer7 Microsoft C# .NET 2 23rd Jun 2004 04:47 PM
Re: Strongly Typed Colection of interfaces Aravind C Microsoft C# .NET 0 28th Feb 2004 06:00 PM
Pocket Excel colection of data John Alderman Microsoft Excel Worksheet Functions 0 28th Jun 2003 03:42 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:15 PM.