O
Otis Mukinfus
I've been wrestling with this for a while and can't figure it out.
I have a generic method with the following signature:
//this compiles OK
public abstract class DataMethod
{
public abstract T Select<T>();
}
I want to call it like this:
public override T Select<T>()
{
......
}
But when I compile I get various types of compile errors depending on how I try
to do the code in the overridden method.
Here is what I have tried:
public override T Select<T>()
{
T = new Dictionary<string, DxccCountry>();
}
Error 1 'T' is a 'type parameter' but is used like a 'variable'
I've tried all the ways I know of to get this to work.
T t = new Dictionary<string, DxccCountry>();
Error 1 Cannot implicitly convert type
'System.Collections.Generic.Dictionary<string,N5GE.HamLib.Core.DxccCountry>' to
'T'
Is it not possible to use a generic method with a return type without passing it
into the method as a parameter?
Good luck with your project,
Otis Mukinfus
http://www.arltex.com
http://www.tomchilders.com
I have a generic method with the following signature:
//this compiles OK
public abstract class DataMethod
{
public abstract T Select<T>();
}
I want to call it like this:
public override T Select<T>()
{
......
}
But when I compile I get various types of compile errors depending on how I try
to do the code in the overridden method.
Here is what I have tried:
public override T Select<T>()
{
T = new Dictionary<string, DxccCountry>();
}
Error 1 'T' is a 'type parameter' but is used like a 'variable'
I've tried all the ways I know of to get this to work.
T t = new Dictionary<string, DxccCountry>();
Error 1 Cannot implicitly convert type
'System.Collections.Generic.Dictionary<string,N5GE.HamLib.Core.DxccCountry>' to
'T'
Is it not possible to use a generic method with a return type without passing it
into the method as a parameter?
Good luck with your project,
Otis Mukinfus
http://www.arltex.com
http://www.tomchilders.com