473,382 Members | 1,689 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,382 software developers and data experts.

Expanding Arrays

All

Can someone tell me why the following is considered bad coding practice,
please?

int n = 0;
int m = 1;

ArrayList list = new ArrayList();
list.Add(n);
list.Add(m);

Many thanks in advance!

--
Chris
Nov 24 '06 #1
5 1460
Chris wrote:
Can someone tell me why the following is considered bad coding practice,
please?

int n = 0;
int m = 1;

ArrayList list = new ArrayList();
list.Add(n);
list.Add(m);
It's not, particularly.

In .NET 2.0 it would be better to use a List<intto avoid boxing and
unboxing (and casting) but there's nothing hugely wrong with the above.

Perhaps you could give us more context for your question?

Jon

Nov 24 '06 #2
Erm.. it isn't. That is perfectly fine if "list" represents a changable set
of data, that could later have more or less entries. The only down side is
that it isn't strongly typed, but in 2.0 that can be fixed using List<int>.
Maybe if you know the size in advance you could pre-size it in the ctor...
but there are more important things in life...

Of course, if it will only ever have 2 entries, then int[] may suffice...
but then again even then an array may be overkill...

What makes you think it is bad?
Nov 24 '06 #3
All

Thanks for the replies, and apologies for the misleading subject line -
that's what multitasking on a Friday afternoon does for you.
>Can someone tell me why the following is considered bad coding practice,
please?

int n = 0;
int m = 1;

ArrayList list = new ArrayList();
list.Add(n);
list.Add(m);

It's not, particularly.
[..]
Perhaps you could give us more context for your question?
The question I asked was in an interview test for prospective .NET
developers that I was attempting. I am fairly new to .NET and C#, so I was
wondering if there was something that I was missing. Then only thing that I
could see was that with a fixed length collection such as this, one could
use a strongly typed Array ionstead of the ArrayList. From your responses it
seems that this is the correct answer.

Thanks!

--
Chris
Nov 24 '06 #4
The code is quite good... Nothing much wrong there.
it can be improved as per the above suggestions...

one more better point that we can include is fixing the side of list if
you can guess it approximately other wise it is quite good code.

Thanks
-Cnu.
Chris wrote:
All

Can someone tell me why the following is considered bad coding practice,
please?

int n = 0;
int m = 1;

ArrayList list = new ArrayList();
list.Add(n);
list.Add(m);

Many thanks in advance!

--
Chris
Nov 27 '06 #5
Please explain what strongly typed means

Thankyou

Nov 27 '06 #6

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

Similar topics

1
by: Jeffrey Kilpatrick | last post by:
I have a SQL 6.5 database that we parse some data into everyday using an access program. All this was devises and setup by a programmer that I can't get in contact with anymore and it has actually...
4
by: David | last post by:
It's sad to say, but when using the AOL web site, like to send an email, they have a nifty capability such that when a window is resized, the textarea where the message is input expands not only...
4
by: erikd | last post by:
I'm using an expanding tree menu based on the design from Dieter Bungers GMD (www.gmd.de) and infovation (www.infovation.de) named displayToc.js. The problem is that the script isn't working...
2
by: weston | last post by:
So, I'm attempting to code an expanding tree menu, based off of unordered lists containing unordered lists. I'm also trying to do it in such a way that none of the javascript has to go inline with...
1
by: Bhiksha Raj | last post by:
Hi, I created an expanding menu on one of the frames in my webpage using code I got from http://www.dynamicdrive.com/dynamicindex1/navigate1.htm I have embedded the code (with minor...
6
by: Jack | last post by:
Hello, I would like some advice on how to disable the behavior of treeviews to expand and collapse when double clicked upon, but still allow the user to use the plus and minus on each node. ...
28
by: braver | last post by:
I need a magical expanding hash with the following properties: * it creates all intermediate keys meh = 1 -- works even if meh didn't exist before * allows pushing new elements to leaves...
13
Chrisjc
by: Chrisjc | last post by:
I am in need of an expanding and collapsing code… The goal is To be able to click a PICTURE IMAGE and expand to show information Reason for this is I have 3 TABLES of information of about ...
36
by: James Harris | last post by:
Initial issue: read in an arbitrary-length piece of text. Perceived issue: handle variable-length data The code below is a suggestion for implementing a variable length buffer that could be used...
19
by: John Whitworth | last post by:
Hi, Firstly, apologies if what I am asking seems really obvious. I'm a self-taught VB2008 (via VB4, VB6 and VB2003) user, and have always just picked up what I need to know, when I need to know...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.