C # - Common Interfaces

Where are common interfaces very useful? (I'm a beginner, so a simple example will certainly be helpful).

+3
source share
3 answers

This is useful when you need an interface, but you also need to abstract away from 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; } }
}
+5
source

You can look IEnumerable<T>for a start.

+3
source

, . IEnumerable IEnumerable<T>. Objects, , T.

, , , .

+2

Source: https://habr.com/ru/post/1722761/


All Articles