Is the condition in a for loop evaluated each iteration?

前端 未结 4 512
忘了有多久
忘了有多久 2020-12-17 08:02

When you do stuff like:

for (int i = 0; i < collection.Count; ++i )

is collection.Count called on every iteration?

Would the res

4条回答
  •  长情又很酷
    2020-12-17 08:25

    Side note, this is NOT checked for every interation in VB.

    Unlike C#, VB caches the result of the collection.Count.

    EDIT:

    The literal VB version of the C# for loop is:

    Dim i = 0
    Do While i < collection.Count
        'code goes here
        i+=1
    Loop
    

提交回复
热议问题