They will both have the same result. On the second method, during the code execution, the pre-processor (or whatever C# does internally) will have to store the list somewhere in order to loop it, you may get about 3 or 4 less instructions on your IL code (or whatever, I'm not .NET expert
) nothing to worry about
But I would suggest you to use the first example, since RunUO's default codes uses it, you may also notice after the execution is done, they call eable.Free(). I don't really know why and what it does (I've not peeked this part of the code yet) but if it is there, there is a reason. I'd guess it will free the memory used by the eable
(Scripts/Spells/Seventh/ChainLightning.cs)
C#:
if ( map != null )
{
IPooledEnumerable eable = map.GetMobilesInRange( new Point3D( p ), 2 );
foreach ( Mobile m in eable )
{
if ( Core.AOS && m == Caster )
continue;
if ( SpellHelper.ValidIndirectTarget( Caster, m ) && Caster.CanBeHarmful( m, false ) )
{
if ( Core.AOS && !Caster.InLOS( m ) )
continue;
targets.Add( m );
if ( m.Player )
playerVsPlayer = true;
}
}
eable.Free();
}