.Net is known for its array covariance. That means that any array can be cast to
an array of base elements:
public class T: B
T tlist = ...
B blist = tlist;
This feature comes at cost:
B b = ...
T t = ...
blist = b; // This efficiently is: blist = (T)b;
tlist = t; // This is the same: tlist = (T)t;
We pay the cost of additional cast, just for nothing. Let this dubious design decision opresses .Net/Java inventors.
You can eliminate the cast. Just use array of structs:
public T t;
S<T> slist = ...
slist.t = t; // Works without cast.
Measurment show that S is ~35% faster than T on write, and slower (JIT could do better) on read.
Well, ugly workaround of ugly design.
P.S. In java there is no relief...
a@href@title, b, blockquote@cite, em, i, strike, strong, sub, super, u