In other words, which of the following would be faster, if any?
List<MyClass> myList;
...
...
foreach (Whatever whatever in SomeOtherLongList)
{
...
if (i < myList.Count)
{
...
}
}
or
List<MyClass> myList;
...
...
int listCount = myList.Count;
foreach (Whatever whatever in SomeOtherLongList)
{
...
if (i < listCount)
{
...
}
}
Thanks :)
The Count
is just an integer. it doesnt get calculated when you ask its value. it's 'pre-calculated' so it's the same. option 1 is more readable :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With