Hi folks!
Well, take a look:
int nfiles = arrArchives.Count;
Stream st = null;
for (int i = 0; i <= nfiles; i++)
{
st = arrArchives[i];
}
So, I want add arraylist items into "st" stream, how to do this?
This below code don´t works, the error: "Cannot convert source type 'object' to target type 'System.IO.Stream'"
Thanks in advanced :)
Loading
Posted Apr 24, 2008, 7:14 PM
List<Stream> arrArchives = new List<Stream>();
This will create a generic collection much like the ArrayList, except no casting is involved. So instead of storing objects in the collection, your storing Stream objects, which makes it much more typesafe because when you use the collection, you will already know whats stored in it and wont have to backtrack or remember.
Posted Apr 24, 2008, 7:07 PM
int nfiles = arrArchives.Count;
Stream st = null;
for (int i = 0; i <= nfiles; i++)
{
st = (Stream)arrArchives[i];
}
Althought its seems kind of redundant, lol.
However, if the objects you are storing in the arraylist arent of type Stream or derive from Stream, you will get an InvalidCastException.
If your just trying to write to the stream, you will need to initalize the stream before you can write to it. If you just want to store the data, you can use a MemoryStream, something like this:
int nfiles = arrArchives.Count;
Stream st = new MemoryStream();
for (int i = 0; i <= nfiles; i++)
{
//This will cause a compile error though...
st.Write(arrArchives[i]);
}
But we need to know what your storing in the ArrayList collection before we can get any further :)