Armando
Wed Jul 02 10:19:51 CDT 2008
Hi,
my arraylist collect string types.
I read lines from a text file, and i add to arraylist each line:
TextReader sr = new StreamReader(PATH+ @"\LOG.txt");
String sLine = "";
aList = new ArrayList();
while ((sLine = sr.ReadLine()) != null)
{
if (Count > 0)
{
//### ARRAYLIST ####
aList.Add(sLine);
}
Count++;
}
sr.Close();
//After i want convert my ArrayList (aList) to byte array like you tould;
if (aList.Count > 0)
byte[] array = (byte[])aList.ToArray(typeof(string));
but its give me a InvalidCastException.
I hope that sample above helps you to help me... :)
--
Armando Rocha
Mobile Developer
http://www.ifthensoftware.com
PORTUGAL
"Neil Cowburn" <neilc@[nospam]opennetcf.[nospam]com> escreveu na mensagem
news:2008070215371143658-neilc@nospamopennetcfnospamcom...
> On 2008-07-02 15:08:41 +0100, "Armando Rocha"
> <armandorocha@ifthensoftware.com> said:
>
>> when a try run your code ( byte[] array = (byte[])list.ToArray(typeof
>> (Byte));) its give me a InvalidCastException.
>
> The InvalidCastException tells me that the ArrayList, list, contains types
> that are not of type Byte.
>
> If you want to convert an ArrayList that's populated like this:
>
> ArrayList list = new ArrayList();
> list.Add("one");
> list.Add(2);
> list.Add(true);
>
> then you need to enumerate each element in the ArrayList and manually
> convert to bytes.
>
> --
> Neil Cowburn MVP
> Principal Partner
> OpenNETCF Consulting
>