Guest User

Untitled

a guest
Dec 14th, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. static void Main(string[] args)
  2. {
  3.     int a = 123;
  4.     int? b = null;
  5.     object c = new object();
  6.     object d = null;
  7.     int? e = 456;
  8.     var f = (int?)789;
  9.     bool result1 = ValueTypeHelper.IsNullable(a); // false
  10.     bool result2 = ValueTypeHelper.IsNullable(b); // true
  11.     bool result3 = ValueTypeHelper.IsNullable(c); // false
  12.     bool result4 = ValueTypeHelper.IsNullable(d); // false
  13.     bool result5 = ValueTypeHelper.IsNullable(e); // true
  14.     bool result6 = ValueTypeHelper.IsNullable(f); // true
  15.  
  16. }
  17.  
  18. public static class ValueTypeHelper
  19. {
  20.     public static bool IsNullable<T>(T t) { return false; }
  21.     public static bool IsNullable<T>(T? t) where T : struct { return true; }
  22. }
Add Comment
Please, Sign In to add comment