Click here to Skip to main content
15,881,172 members
Articles / Programming Languages / C#

Alternative to Activator.CreateInstance

Rate me:
Please Sign up or sign in to vote.
4.67/5 (4 votes)
26 Jan 2012CPOL 18.8K   3  
Using expressions, you can achieve a faster result with less code.public static T New(){ Type t = typeof(T); Func method = Expression.Lambda>(Expression.Block(t, new Expression[] { Expression.New(t) })).Compile(); return method();}Furthermore, this can...

Views

Daily Counts

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Architect
United States United States
Since I've begun my profession as a software developer, I've learned one important fact - change is inevitable. Requirements change, code changes, and life changes.

So..If you're not moving forward, you're moving backwards.

Comments and Discussions