Category: generics

How to initialize a List to a given size (as opposed to capacity)?

.NET offers a generic list container whose performance is almost identical (see Performance of Arrays vs. Lists question). However they are quite different in initialization. Arrays are very easy to initialize with a default value, and by definition they already have certain size: string[] Ar = new string[10]; Which allows one to safely assign random […]