B
Benny
I just wanted to throw the discussion out there on what the best
practice people feel is for using large objects in a foreach loop. For
example if you are reusing an Image object in a loop like this (letters
above snippets are for reference purposes):
A
foreach ( string s in myList )
{
Image img = Image.FromFile( s );
// operate on img
}
would it run more efficiently like this?
B
Image img = null;
foreach ( string s in myList )
{
img = Image.FromFile( s );
// operate on img
}
or
C
foreach ( string s in myList )
{
using ( Image img = Image.FromFile( s );
{
// operate on img
}
}
the list goes on....
Let me know what your thoughts are.
practice people feel is for using large objects in a foreach loop. For
example if you are reusing an Image object in a loop like this (letters
above snippets are for reference purposes):
A
foreach ( string s in myList )
{
Image img = Image.FromFile( s );
// operate on img
}
would it run more efficiently like this?
B
Image img = null;
foreach ( string s in myList )
{
img = Image.FromFile( s );
// operate on img
}
or
C
foreach ( string s in myList )
{
using ( Image img = Image.FromFile( s );
{
// operate on img
}
}
the list goes on....
Let me know what your thoughts are.