fork download
  1. using System;
  2.  
  3. public class Test
  4. {
  5. public class DictBase
  6. {
  7. public int Val;
  8. }
  9.  
  10. class Dict1 : DictBase
  11. {
  12. public int GetVal()
  13. {
  14. return Val;
  15. }
  16. }
  17. class ConvertBase<T> where T : DictBase
  18. {
  19. public T _dict;
  20.  
  21. public ConvertBase()
  22. {
  23. _dict = new T();
  24.  
  25. }
  26.  
  27. public void GetSome()
  28. {
  29. var t = _dict.Val;
  30. }
  31. }
  32.  
  33. class Convert1 : ConvertBase<Dict1>
  34. {
  35. public void DoWork()
  36. {
  37. var t = _dict.GetVal();
  38. }
  39. }
  40. public static void Main()
  41. {
  42. // your code goes here
  43. }
  44. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cs(23,21): error CS0304: Cannot create an instance of the variable type `T' because it does not have the new() constraint
Compilation failed: 1 error(s), 0 warnings
stdout
Standard output is empty