ThreadStatic v.s. ThreadLocal<T>: is generic better than attribute?
问题 [ThreadStatic] is defined using attribute while ThreadLocal<T> uses generic. Why different design solutions were chosen? What are the advantages and disadvantages of using generic over attributes in this case? 回答1: Something the blog post noted in the comments doesn't make explicit, but I find to be very important, is that [ThreadStatic] doesn't automatically initialize things for every thread. For example, say you have this: [ThreadStatic] private static int Foo = 42; The first thread that