fork download
  1. // ===++===
  2. //
  3. // OrtizOL
  4. //
  5. // ===--===
  6. /*============================================================
  7. //
  8. // Clase: ClaseGenerica.cs
  9. //
  10. // Propósito: Uso de restricción de parámetros de tipo.
  11. //
  12. ============================================================*/
  13.  
  14. using System;
  15.  
  16. namespace Articulos.Cap03
  17. {
  18. internal class A { }
  19.  
  20. internal class B : A { }
  21.  
  22. internal class C : B { }
  23.  
  24. internal class D : Object { }
  25.  
  26. internal class ClaseGenerica<T> where T:A
  27. {
  28. // Cuerpo de implementación
  29. }
  30.  
  31. internal class PruebaClaseGenerica
  32. {
  33. public static void Main()
  34. {
  35. ClaseGenerica<A> a = new ClaseGenerica<A>();
  36. ClaseGenerica<B> b = new ClaseGenerica<B>();
  37. ClaseGenerica<C> c = new ClaseGenerica<C>();
  38.  
  39. ClaseGenerica<D> d = new ClaseGenerica<D>();
  40. }
  41. }
  42. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cs(39,13): error CS0311: The type `Articulos.Cap03.D' cannot be used as type parameter `T' in the generic type or method `Articulos.Cap03.ClaseGenerica<T>'. There is no implicit reference conversion from `Articulos.Cap03.D' to `Articulos.Cap03.A'
prog.cs(26,20): (Location of the symbol related to previous error)
prog.cs(39,38): error CS0311: The type `Articulos.Cap03.D' cannot be used as type parameter `T' in the generic type or method `Articulos.Cap03.ClaseGenerica<T>'. There is no implicit reference conversion from `Articulos.Cap03.D' to `Articulos.Cap03.A'
prog.cs(26,20): (Location of the symbol related to previous error)
Compilation failed: 2 error(s), 0 warnings
stdout
Standard output is empty