Reputation: 10499
I have my generic class and two methods that accept as argument a delegate (generic or not)
public sealed class MyClass<TResult>
{
public MyClass ContinueWith(ThreadInfo.Parameterized arg)
{
}
public MyClass<TResult> ContinueWith<TResult>(ThreadInfo<TResult>.Parameterized arg)
{
}
}
Where:
public sealed class MyClass
{
}
I have the Compiler Warning (level3) CS0693 but if I remove <TResult>
from the second method:
public MyClass<TResult> ContinueWith(ThreadInfo<TResult>.Parameterized arg)
I can't use this method anymore, if I try I get a compiler error because the compiler thinks I want to use the first method.
How can I solve this problem?
Upvotes: 0
Views: 1877
Reputation: 16623
You have to use different parameter names. So this depends on what do you want to achieve.
I think you need something like this, where the return type is of type MyClass<TResult>
and you can choose the type for ThreadInfo<>
:
public MyClass<TResult> ContinueWith<T1>(ThreadInfo<T1>.Parameterized arg)
{
//...
}
Or if you want to choose the type only when you create an instance of your object:
public MyClass<TResult> ContinueWith(ThreadInfo<TResult>.Parameterized arg)
{
//...
}
Upvotes: 0
Reputation: 1499770
Well it sounds like you really want:
public MyClass<TResult> ContinueWith(ThreadInfo<TResult>.Parameterized arg)
In other words, using the TResult
parameter declared at the type level.
If you really want it to be a generic method (i.e. introducing a new type parameter) you have to give it a different name:
public MyClass<T2> ContinueWith<T2>(ThreadInfo<T2>.Parameterized arg)
(It's possible that you may want to return a MyClass<TResult>
here, or something similar - we don't really know what you're trying to achieve, which makes it hard to give detailed help.)
Upvotes: 3