using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Collections; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { Nullable<int> nullable = 5; object boxed = nullable; Console.WriteLine(boxed.GetType()); int normal = (int)boxed; Console.WriteLine(normal); nullable = (Nullable<int>)boxed; Console.WriteLine(nullable); nullable = new Nullable<int>(); boxed = nullable; Console.WriteLine(boxed == null); nullable = (Nullable<int>)boxed; Console.WriteLine(nullable.HasValue); Console.ReadKey(); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Collections; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { int? nullable = 5; object boxed = nullable; Console.WriteLine(boxed.GetType()); int normal = (int)boxed; Console.WriteLine(normal); nullable = (int?)boxed; Console.WriteLine(nullable); nullable = new int?(); boxed = nullable; Console.WriteLine(boxed == null); nullable = (int?)boxed; Console.WriteLine(nullable.HasValue); Console.ReadKey(); } } }