Generics - A question on generics - delegates - runtime binding.

Tech-Archive recommends: Fix windows errors by optimizing your registry



I would like to do the following and cannot figure it out.

public class A<T>
{
public delegate T GetValueDelegate(A<T> var);
public GetValueDelegate GetValue = new GetValueDelegate(B.GetValue);
}

public class B
{
public static int GetValue(A<int> var)
{
//do something and return int
}

public static float GetValue(A<float> var)
{
//do something and return float
}

public static string GetValue(A<string> var)
{
//do something and return string
}

//or in general
public static SomeType GetValue(A<SomeType> var)
{
//do something specific for type SomeType and return that SomeType
}
}

Now:-----------------------------------
I was thinking when I do

....somewhere in some code....
A<int> s = new A<int>();

that on creation of this instance of A of type int that the delegate
in A would find the proper overload in class B such that:
....
int I = s.GetValue();
....
would resolve to the class B's method
....
public static int GetValue(A<int> var)
....
and this would occur dynamically at runtime.


The short is that I get a 'No Overload Error' as follows.
'No overload for 'GetValue' matches delegate 'A<T>.GetValueDelegate'

I am obviously not understanding something. Help would be greatly appriciated.

k


--
A single 20-watt compact fluorescent lamp used in place of a 75-watt
incandescent will save about 550 kilowatt-hours over its lifetime. That is
500 pounds of coal; a pile the size of your office desk.
.



Relevant Pages