Where do generic interfaces are quite useful ? ( I am a beginner,so simple example will definitely helpful).
Its useful when you need an interface, but you also need to abstract the data type. Simple example
public interface IMyShape<T>
{
T X { get; }
T Y { get; }
}
public class IntSquare : IMyShape<int>
{
int X { get { return 100; } }
int Y { get { return 100; } }
}
public class IntTriangle : IMyShape<int>
{
int X { get { return 200; } }
int Y { get { return 200; } }
}
public class FloatSquare : IMyShape<float>
{
float X { get { return 100.05; } }
float Y { get { return 100.05; } }
}
You can look at IEnumerable<T> to begin with.
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