Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static void Main(string[] args)
- {
- int a = 123;
- int? b = null;
- object c = new object();
- object d = null;
- int? e = 456;
- var f = (int?)789;
- bool result1 = ValueTypeHelper.IsNullable(a); // false
- bool result2 = ValueTypeHelper.IsNullable(b); // true
- bool result3 = ValueTypeHelper.IsNullable(c); // false
- bool result4 = ValueTypeHelper.IsNullable(d); // false
- bool result5 = ValueTypeHelper.IsNullable(e); // true
- bool result6 = ValueTypeHelper.IsNullable(f); // true
- }
- public static class ValueTypeHelper
- {
- public static bool IsNullable<T>(T t) { return false; }
- public static bool IsNullable<T>(T? t) where T : struct { return true; }
- }
Add Comment
Please, Sign In to add comment