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
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 said:
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
.