fork download
  1. public class Program {
  2. public static void Main() {
  3. var dog = new Cachorro() { Nome = "Toy", Patas = 4, MesesGestacao = 3, Especie = "Cachorro" };
  4. IPet<Animal> p1 = new Pet<Cachorro>();
  5. }
  6. }
  7. class Animal {
  8. public string Especie { get; set; }
  9. }
  10. class Mamifero : Animal {
  11. public int MesesGestacao { get; set; }
  12. }
  13. class Cachorro : Mamifero {
  14. public string Nome { get; set; }
  15. public int Patas { get; set; }
  16. }
  17. interface IPet<out T> where T : Animal {
  18. string Apelido { get; set; }
  19. }
  20. class Pet<T> : IPet<T> where T : Animal {
  21. public string Apelido { get; set; }
  22. }
  23.  
  24. //https://pt.stackoverflow.com/q/508268/101
Success #stdin #stdout 0.01s 20032KB
stdin
Standard input is empty
stdout
Standard output is empty