using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Variance
{
class A { }
class B : A { }
class C<out T> { }
class Program
{
static void Main(string[] args)
{
var v = new C<B>();
CA(v);
}
static void CA(C<A> v) { }
}
}
Invalid variance modifier. Only interface and delegate type parameters can be specified as variant Ask Question Asked11 years, 11 months ago Active4 years, 4 months ago Viewed5k times 10
Invalid variance: The type parameter ‘T’ must be covariantly valid on ‘IBuildingManager<T>.Sell ()’. ‘T’ is contravariant. Covariance (<out T>) – Example! Again, we have an interface with specified variance – this time covariance. Which of course means, type T can only be returned by ICarManager ’s methods.
Only interface and delegate type parameters can be specified as variant Ask Question Asked11 years, 11 months ago Active4 years, 4 months ago Viewed5k times 10
After you update, you may get this error: "Invalid variant operation". To fix this you may need to force the next update. Occasionally after an Acclipse Document Manager update is released some clients have report they start having issues with filing, closing emails and so on.
This is the offending line:
class C<out T>
As the error message tells you, you can't apply generic variance to classes, only to interfaces and delegates. This would be okay:
interface C<out T>
The above is not.
For details, see Creating Variant Generic Interfaces
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With