Geeks With Blogs
John Conwell: aka Turbo Research in the visual exploration of data June 2008 Entries
Creating an instance of a generic paremeter is slooooo: part deux
For grins I looked at my code that calls: T tmp = new T(); in Reflector, so see if it could shed any light into T instance creation badness. Well, it turns out that the C# compiler spits out code to call Activator.CreateInstance T tmp = Activator.CreateInstance<... I kind of get why the C# compiler does this, because it doesnt know what T is at compile time. But at run time the JIT compiler DOES know. I'm surprised that the C# team didn't build in the smarts to JIT code to explicitly call ......

Posted On Friday, June 13, 2008 12:30 PM

Creating an instance of a generic paremeter is slooooo
I recently needed to change how an array lookup worked to make it more efficient, and decided to use the List<T>.BinarySearch to do the lookup. The class that contained this lookup had a generic parameter, and was constrained like so: public class SortedNameList<T> where T : class, INameValueItem, new() {...} where the T of List<T> was the same as the class generic parameter. In order to do the BinarySearch, List<T> required an input of type T to search against. Since I only ......

Posted On Friday, June 13, 2008 8:40 AM

Copyright © John Conwell | Powered by: