Can Arraylist store string aswell as integer values

  • Thread starter Thread starter Vaj
  • Start date Start date
V

Vaj

Hi,
I'm attaching a code here.this code works successfully,
But my doubt is,
Can an arraylist store this integer value "J" as wellas string value "S"
ArrayList ArrMM=new ArrayList();

for(int j=1;j<=12;j++)

{if(j<10)

{string s="0" + j;ArrMM.Add(s);}

else {ArrMM.Add(j);} }

Can anyone help me for solving this problem?.

thanks,
Vaj.
 
Hi,
The ArrayList can store any reference types and boxed value types.
Here is another way:

ArrayList ArrMM=new ArrayList();
for(int j=1;j<=12;j++)
{
ArrMM.Add(j.ToString("00"));
}

The ArrMM will contain 12 strings "01", "02", ... "11", "12".
In your example, the ArrMM will contain 9 strings "01", "02" .. "09" and 3
boxed integers 10, 11, 12
 
Back
Top