fork download
  1. using static System.Console;
  2. using System.Collections.Generic;
  3.  
  4. using System;
  5.  
  6. public class Program {
  7. public static void Main() {
  8. WriteLine(typeof(Nullable).Name);
  9. WriteLine(typeof(Nullable<>).Name);
  10. int? nInt = 0;
  11. decimal? nDecimal = 0M;
  12. List<int> lInt = new List<int>();
  13. int xInt = 1;
  14. string xString = "";
  15. decimal xDecimal = 2M;
  16. Dictionary<string, int> dStingInt = new Dictionary<string, int>();
  17. PrintObject<int?>(nInt);
  18. PrintObject<decimal?>(nDecimal);
  19. PrintObject<List<int>>(lInt);
  20. PrintObject<int>(xInt);
  21. PrintObject<string>(xString);
  22. PrintObject<decimal>(xDecimal);
  23. PrintObject<Dictionary<string, int>>(dStingInt);
  24. }
  25. private static void PrintObject<T>(T obj) {
  26. var type = typeof(T);
  27. var generic = type.IsGenericType;
  28. var nullable = generic && type.GetGenericTypeDefinition() == typeof(Nullable<>);
  29. WriteLine($"{type.Name} - {type.IsGenericType} - {(generic ? type.GetGenericTypeDefinition().Name : (""))} - {(nullable ? Nullable.GetUnderlyingType(type).Name : (""))} - {type.Name}\n");
  30. }
  31. }
  32.  
  33. //https://pt.stackoverflow.com/q/185142/101
Success #stdin #stdout 0.02s 16372KB
stdin
Standard input is empty
stdout
Nullable
Nullable`1
Nullable`1 - True - Nullable`1 - Int32 - Nullable`1

Nullable`1 - True - Nullable`1 - Decimal - Nullable`1

List`1 - True - List`1 -  - List`1

Int32 - False -  -  - Int32

String - False -  -  - String

Decimal - False -  -  - Decimal

Dictionary`2 - True - Dictionary`2 -  - Dictionary`2