c# - Why would I use Enumerable.ElementAt() versus the [] operator? -


It looks like a silly question, but I have not found the answer, so here it is. :)

If you fail to check the extent of your collection, in both cases, you will get an "out-of-range" exception. Is it just coding the preference of style?

And if someone needs an example:

  list & lt; Byte & gt; MyList = new list & lt; Byte & gt; () {0x01, 0x02, 0x03}; Byte Testbyte = myList.ElementAt (2);   

vs

  byte testbyte = mylist [2];    

Because numeric is more common, and one of the collections

But, if this happens - if you do not use ElementAt () then it probably will not be efficient.

Comments