Re: Generics - A question on generics - delegates - runtime binding.
- From: "Bernhard Huemer" <bernhard.huemer@xxxxxxxxx>
- Date: Fri, 22 Jul 2005 22:11:40 +0200
Hello,
//or in general
public static SomeType GetValue(A<SomeType> var)
{
//do something specific for type SomeType and return that SomeType
}
I think you've supposed GetValue to be a generic method but it isn't. Therefore no signature matches the on of your delegate.
public class B
{
// ... public static SomeType GetValue<SomeType>(A<SomeType> var)
{
// ...
}
}Btw. the overloaded versions won't get called, whether the signature matches or not.
greets
On Fri, 22 Jul 2005 18:05:02 +0200, bigtexan <bigtexan@xxxxxxxxxxxxx> wrote:
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
.
- References:
- Prev by Date: Encrypt Database Data
- Next by Date: Re: Modifiers of controls in an inherited form question
- Previous by thread: Re: Generics - A question on generics - delegates - runtime bindin
- Next by thread: RE: Generics - A question on generics - delegates - runtime binding.
- Index(es):
Relevant Pages
|