Hi Joe Enos
I'm not so sure about the problem but....
when you use the operator ":", the left side (when the clausule is true) and right (when it's false) has to have the same type
int myint = b ? 1 : 2;
Because exists the conversion because int is a well-known datatype in .net.
When you pass the name of two methods
Func<int> myFunc = b ? DoSomething : DoSomethingElse;
The compiler screams:
there is no implicit conversion between 'method group' and 'method group'
I think the compiler don't know exactly the type, so you have to inform to the compiler explicitily
So see this
class Teste
{
public static int DoSomething() { return 1; }
public static int DoSomethingElse() { return 2; }
public static bool GetSomeBoolean(){return true;}
public static void Main(string[] args)
{
bool b = GetSomeBoolean();
Func<int> myFunc = b ? (Func<int>)DoSomething : (Func<int>)DoSomethingElse;
System.Console.WriteLine(myFunc().ToString());
}
}
public delegate int Func<T>();
Compile ? yes
execute ? yes
So, I think the reason is that you have to inform to the compiler explicity the type. Since delegate is a class, you can use a simple explicit cast (Func<int>), ok ?
I am not so sure....but i think this is the way...
Best Regards
Does
--
Paulo Alexandre Costa
Universidade Estadual do Ceará - UECE
Great-Ufc Desenvolvedor .Net
Linux User #464032
"A velocidade impressionante dos computadores é de utilidade limitada se os programas que neles rodam usam algoritmos ineficientes."