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

ArrayLists question...

Hi,

I want to store n structures(class) in a Array (I don't
know if it is a god method like this but...)

Anyone knows how can I access an element of the Array?
Array.item(Class).property..?

Here is the code I have
ArrayList ColModulos = new ArrayList();
declaracoes ClsDeclaracoes = new declaracoes();

for ( int i = 0; i<20; i++ )
{
ClsDeclaracoes.MSG_STR="TESTE" + i;
ColModulos.Add(ClsDeclaracoes);
}

Thanks,
BP
Nov 15 '05 #1
6 1111

ColModulos [n] where n is the index of the one you want to play with

Hope that helps

"Bernardo" <bp****@sapo.pt> wrote in message
news:11*****************************@phx.gbl...
Hi,

I want to store n structures(class) in a Array (I don't
know if it is a god method like this but...)

Anyone knows how can I access an element of the Array?
Array.item(Class).property..?

Here is the code I have
ArrayList ColModulos = new ArrayList();
declaracoes ClsDeclaracoes = new declaracoes();

for ( int i = 0; i<20; i++ )
{
ClsDeclaracoes.MSG_STR="TESTE" + i;
ColModulos.Add(ClsDeclaracoes);
}

Thanks,
BP

Nov 15 '05 #2
HI Bernardo,

The problem is cause ArrayList is a array of instances of object. not of
ClsDeclaracoes .

You can do two things:
1- Cast it back:
(( ClsDeclaracoes )ColModulos[index]).Property

2- Use an strong typed collection , this is what I recommend. If you don;t
how to do it just let me know and I will give you an implementation of it
where you only have to change the type.
Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Bernardo" <bp****@sapo.pt> wrote in message
news:11*****************************@phx.gbl...
Hi,

I want to store n structures(class) in a Array (I don't
know if it is a god method like this but...)

Anyone knows how can I access an element of the Array?
Array.item(Class).property..?

Here is the code I have
ArrayList ColModulos = new ArrayList();
declaracoes ClsDeclaracoes = new declaracoes();

for ( int i = 0; i<20; i++ )
{
ClsDeclaracoes.MSG_STR="TESTE" + i;
ColModulos.Add(ClsDeclaracoes);
}

Thanks,
BP

Nov 15 '05 #3
Hi,

Thanks, Can you send me some examples of Typed collection
array.
Thanks a lot

-----Original Message-----
HI Bernardo,

The problem is cause ArrayList is a array of instances of object. not ofClsDeclaracoes .

You can do two things:
1- Cast it back:
(( ClsDeclaracoes )ColModulos[index]).Property

2- Use an strong typed collection , this is what I recommend. If you don;thow to do it just let me know and I will give you an implementation of itwhere you only have to change the type.
Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Bernardo" <bp****@sapo.pt> wrote in message
news:11*****************************@phx.gbl...
Hi,

I want to store n structures(class) in a Array (I don't
know if it is a god method like this but...)

Anyone knows how can I access an element of the Array?
Array.item(Class).property..?

Here is the code I have
ArrayList ColModulos = new ArrayList();
declaracoes ClsDeclaracoes = new declaracoes();

for ( int i = 0; i<20; i++ )
{
ClsDeclaracoes.MSG_STR="TESTE" + i;
ColModulos.Add(ClsDeclaracoes);
}

Thanks,
BP

.

Nov 15 '05 #4
Hi.
I also use ArrayList to put datas from database,using
SQLdatareader, into dropdown list. I want to convert item
from that dropdownlist to integer.How to do that?
Thank you
Nov 15 '05 #5
Hi,

You can use:
int i = Convert.ToInt32( dropdownlistControl.SelectedValue);

Please be aware that this does not checks for possible errors.

Thank,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"djozy" <an*******@discussions.microsoft.com> wrote in message
news:0e****************************@phx.gbl...
Hi.
I also use ArrayList to put datas from database,using
SQLdatareader, into dropdown list. I want to convert item
from that dropdownlist to integer.How to do that?
Thank you

Nov 15 '05 #6
Hi,

Find below the code of a Strong typed collection, I already set the type to
ClSDeclaracoes.

Hope this help,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
//******************************* CODE START
using System;

using System.Collections;

public class ClsDeclaracoesCollection:CollectionBase
{
public ClsDeclaracoes Insert( int index, ClsDeclaracoes newelem )
{
this.InnerList.Insert( index, newelem);
return newelem;
}
public ClsDeclaracoes Add( ClsDeclaracoes newelem)
{
this.InnerList.Add( newelem);
return newelem;
}

public ClsDeclaracoes this[int index]
{
get
{
return (ClsDeclaracoes) InnerList[index];
}
set
{
InnerList[index] = value;
}
}

//You may have to change this to refrect your correct ID name/type
public ClsDeclaracoes Find(int id)
{
foreach(ClsDeclaracoes current in InnerList)
if ( current.ID == id )
return current;
return null;
}

public void Remove( ClsDeclaracoes elem)
{
InnerList.Remove( elem);

}
public ClsDeclaracoesCollection(){}
private ClsDeclaracoesCollection( ArrayList newarray)
{
InnerList.Clear();
foreach( ClsDeclaracoes location in newarray)
{
Add( location);
}
}

public ClsDeclaracoesCollection Clone()
{
return new ClsDeclaracoesCollection( InnerList);
}
}
//******************************* CODE END

<an*******@discussions.microsoft.com> wrote in message
news:0e****************************@phx.gbl...
Hi,

Thanks, Can you send me some examples of Typed collection
array.
Thanks a lot

-----Original Message-----
HI Bernardo,

The problem is cause ArrayList is a array of instances

of object. not of
ClsDeclaracoes .

You can do two things:
1- Cast it back:
(( ClsDeclaracoes )ColModulos[index]).Property

2- Use an strong typed collection , this is what I

recommend. If you don;t
how to do it just let me know and I will give you an

implementation of it
where you only have to change the type.
Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Bernardo" <bp****@sapo.pt> wrote in message
news:11*****************************@phx.gbl...
Hi,

I want to store n structures(class) in a Array (I don't
know if it is a god method like this but...)

Anyone knows how can I access an element of the Array?
Array.item(Class).property..?

Here is the code I have
ArrayList ColModulos = new ArrayList();
declaracoes ClsDeclaracoes = new declaracoes();

for ( int i = 0; i<20; i++ )
{
ClsDeclaracoes.MSG_STR="TESTE" + i;
ColModulos.Add(ClsDeclaracoes);
}

Thanks,
BP

.

Nov 15 '05 #7

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

Similar topics

0
by: James | last post by:
I see that variations on this question have appeared before but I'm still completely stumped. I'm developing an application with a fairly robust graphics component for 3D rendering. I've written...
1
by: godsella | last post by:
First i have two stored procedures, i have passed the values of each one into two different arraylists of dates. how can i compare the two arraylists of dates? Thanks in advance
5
by: Dennis | last post by:
NOTE: This is a COMMENT...not a QUESTION: For the newbies, I've been messing around with strongly typed ArrayLists so I don't have to type so many "DirectCast". The following works great where...
5
by: drdave | last post by:
I would like to have ten arraylists created within a loop.. is there a conversion or something I can do to acheive this.. pseudo: Dim counter As Integer = 0 Dim ArrName As ArrayList ...
0
by: steve | last post by:
I'm looking for a code example how to compare the values in a given record in different arraylists two arraylists, two fields in each record, both defined as string I'm thinking that it's...
3
by: steve | last post by:
I need to compare the value of a field in a row on an arraylist with the value of a field on a second arraylist I have this bit of code working for arrays but cant get it working for arraylists The...
4
by: Andy in S. Jersey | last post by:
I would like to create an unknown number of Arraylists, meaning, I don't know how many I should create until runtime. I will be reading a table, and 0,1,2, or more fields have to be put into...
2
by: Andy in S. Jersey | last post by:
I would like to create an unknown number of ArrayLists, that is I don't know that until runtime. Of course I can do this if I knew I needed two: ArrayList IntervalArray1 = new ArrayList();...
1
by: Newbie19 | last post by:
I'm just learning java arrays/arraylists and was wondering what are the best books for learning java arrays/arraylists? I know practice is the best way to learn, but I have a hard time...
3
by: =?Utf-8?B?Sm9zaFA=?= | last post by:
Hi All, I am attempting to compare values in two arraylists to make sure all the values are the same. I am running into trouble with my code if both arraylists compare okay up until a point and I...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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,...

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.