You are incorrect. If it helps you to appreciate my point, here is a similar
program that creates two delegates, the first one of which triggers the
runtime error and is guarded by a compilation directive.
You can easily control whether the program gets a runtime exception vs runs
successfully, by either commenting out the #define, or not. I hope this
suffices to disprove your claim about T being a placeholder.
#define MAKE_IT_FAIL
using System.Diagnostics;
namespace Test {
public class Program {
public static void Main() {
Func1("hello");
}
private delegate void FuncDelegate<T>(T item);
private static void Func1<T>(T item) {
#if MAKE_IT_FAIL
FuncDelegate<Ttemp1=new FuncDelegate<T>(Func1);
#endif
FuncDelegate<Ttemp2=new FuncDelegate<T>(Func2);
temp2(item);
}
private static void Func2<T>(T item) {
Debug.WriteLine(item);
}
}
}
"Peter Bromberg [C# MVP]" wrote:
Kosak,
Before you start reporting "bugs" , try doing this:
FuncDelegate<stringtemp = new FuncDelegate<string>(Func);
You cannot use "T" as if it were an actual type in the implementation,
its just a placeholder for the actualy type you decide to use.
Hope that helps,
Peter
--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com
"kosak" wrote:
Hello. When I run the program below, I get the exception
System.InvalidProgramException: Common Language Runtime detected an invalid
program. (Visual Studio 2005 version 8.0.50727.51)
I can work around it (by having the delegate point to a helper function).
Basically the purpose of this post is to let someone at Microsoft know about
this bug.
(The generated IL looks OK to me; my guess is that there's a problem in the
verifier.)
namespace Test {
public class Program {
public static void Main() {
Func("hello");
}
private delegate void FuncDelegate<T>(T item);
private static void Func<T>(T item) {
FuncDelegate<Ttemp=new FuncDelegate<T>(Func);
}
}
}