473,407 Members | 2,359 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

Dynamic colection??

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
Jan 1 '07 #1
3 1029
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.comwrote in message
news:e1**************@TK2MSFTNGP02.phx.gbl...
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

Jan 1 '07 #2
"Paez" <marco.pais@[IGNORE]gmail.coma écrit dans le message de news:
e1**************@TK2MSFTNGP02.phx.gbl...

| 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<MyClassgeneric list.

Joanna

--
Joanna Carter [TeamB]
Consultant Software Engineer
Jan 1 '07 #3
Thanks for the answers.

It help a lot...

Paez

"Paez" <marco.pais@[IGNORE]gmail.comwrote in message
news:e1**************@TK2MSFTNGP02.phx.gbl...
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

Jan 1 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Roel Wuyts | last post by:
CALL FOR CONTRIBUTIONS International Workshop on Revival of Dynamic Languages http://pico.vub.ac.be/~wdmeuter/RDL04/index.html (at OOPSLA2004, Vancouver, British Columbia, Canada, October...
1
by: Guinness Mann | last post by:
When you guys talk about "dynamic SQL," to what exactly are you referring? Is dynamic SQL anything that isn't a stored procedure? Specifically, I use ASP.NET to communicate with my SQL Server...
6
by: Materialised | last post by:
Hi Everyone, I apologise if this is covered in the FAQ, I did look, but nothing actually stood out to me as being relative to my subject. I want to create a 2 dimensional array, a 'array of...
3
by: Stephen Gennard | last post by:
Hello, I having a problem dynamically invoking a static method that takes a reference to a SByte*. If I do it directly it works just fine. Anyone any ideas why? I have include a example...
7
by: serge | last post by:
How can I run a single SP by asking multiple sales question either by using the logical operator AND for all the questions; or using the logical operator OR for all the questions. So it's always...
0
by: Pascal Costanza | last post by:
Dynamic Languages Day @ Vrije Universiteit Brussel ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Monday, February 13, 2006, VUB Campus Etterbeek The VUB (Programming Technology Lab,...
7
by: Mike Livenspargar | last post by:
We have an application converted from v1.1 Framework to v2.0. The executable references a class library which in turn has a web reference. The web reference 'URL Behavior' is set to dynamic. We...
1
by: Peterwkc | last post by:
Hello all expert, i have two program which make me desperate bu after i have noticed the forum, my future is become brightness back. By the way, my problem is like this i the first program was...
5
by: bearophileHUGS | last post by:
I often use Python to write small programs, in the range of 50-500 lines of code. For example to process some bioinformatics data, perform some data munging, to apply a randomized optimization...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.