Supposing that SomeMethod has signature
public IEnumerable SomeMethod();
is there any difference between
Assuming you're talking about C#.
foreach translates into something like this:
var enumerable = SomeMethod(); // Or whatever is passed to foreach
var enumerator = enumerable.GetEnumerator();
while (enumerator.MoveNext())
{
...
}
So, as enumerable is needed only once, there will be only one call to SomeMethod even if you put it directly into the foreach statement.