Are C# lists fast? What are the good and bad sides of using lists to handle objects?
Extensive use of lists will make software slower? What are the alternatives to lists in C#?
How many objects is "too many objects" for lists?
Speed of light is now universally represented by symbol 'c'. This symbol originated from the initial letter of the Latin word “celerity” meaning “swift” or “quick”. This symbol was used by Weber and Kohlrausch in their papers in 1856.
Speed of light in air is 3×108 m/s and speed of light in common glass is 2*10^8 m/s. Calculate the refractive index of glass. Answer: The glass refractive index is defined as the ratio between the speed of light in the vacuum and the speed of light in the glass.
The metre is the length of the path travelled by light in vacuum during a time interval of 1/299 792 458 of a second. This defines the speed of light in vacuum to be exactly 299,792,458 m/s. This provides a very short answer to the question "Is c constant": Yes, c is constant by definition!
List<T>
uses a backing array to hold items:
It's generally fine to use lists fairly extensively. If you know the final size when you start populating a list, it's a good idea to use the constructor which lets you specify the capacity, to avoid resizing. Beyond that: if you're concerned, break out the profiler...
Compared to what?
List<T>
, then that is essentially a wrapper around an array; so fast to read/write by index, relatively fast to append (since it allows extra space at the end, doubling in size when necessary) and remove from the end, but more expensive to do other operations (insert/delete other than the end)Dictionary<,>
etc offer better access by keyA list isn't intrinsically slow; especially if you know you always need to look at all the data, or can access it by index. But for large lists it may be better (and more convenient) to search via a key. There are various dictionary implementations in .NET, each with different costs re size / performance.
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