public interface ILovable<T> where T : IEquatable<T>
{
T Care(T t);
}
public class Me : ILovable<int>
{
public int Care(int i)
{
return i;
}
}
Say I have the above. Now below function fails:
private static void Colour<T>(ILovable<T> me) where T : IEquatable<T>
{
var z = me.Care(1); //cannot convert from 'int' to 'T'
}
What's failing the above piece of code? ILovable<T>
has a Care
function which intakes a T
which is IEquatable<T>
. In the above function I'm calling the same Care
function and passing T
which is int
type. int
is after all IEquatable<int>
.
What am I doing wrong? Is there any work around to get it fixed?