C# .First() vs [0]

后端 未结 5 1362
遥遥无期
遥遥无期 2021-02-14 03:48

Interested, does approaches has any differences.
So, I created two snippets.

Snippet A 
List a = new List();
a.Add(4);
a.Add(6);
int         


        
5条回答
  •  失恋的感觉
    2021-02-14 04:15

    If you're asking about asymptotic complexity, both approaches are O(1), use any of it.

    If you're asking about real speed, there's no answer, since it can differ from version to version, from one machine to another. IL you've generated is not the same for any other version of .NET.

    Attempt to optimize your code by choosing one of these approaches is obviously premature optimization.

提交回复
热议问题