http://www.craigslinkedlist.com/posts/stupid_dotnet_tricks_12 asks Hoosgot,
Disclaimer: There may, in fact, be a good reason for the following .NET behavior. However, if there is, it’s certainly not clear to me. I pose a question at the bottom; dear lazyweb, please explain. .NET’s type inference lets you avoid specifying the type of a generic parameter on a method call some, but not all, of the time. Consider the following infrastructure: public String getSomeString() { return “Some String”; } public T returnTheValue<T>(T value) { return value; } public delegate T Factory<T>(); public T createSomeValue<T>(Factory<T> factory) { return factory(); } The following code works fine: Console.WriteLine(returnTheValue(”A String”)); .NET is smart enough to know that, since you’re passing in a String for T, it can assume that String is used … Visit the blog to lend your wisdom, or you can comment below.Stupid .NET Tricks #12
May 15th, 2008 · No Comments
Tags: Uncategorized
0 responses so far ↓
There are no comments yet...Kick things off by filling out the form below.
Leave a Comment