Skip to content

Instantly share code, notes, and snippets.

@admir-live
Created May 15, 2024 07:44
Show Gist options
  • Save admir-live/47de306dcc41ee08dd0ddc5d77e14e35 to your computer and use it in GitHub Desktop.
Save admir-live/47de306dcc41ee08dd0ddc5d77e14e35 to your computer and use it in GitHub Desktop.
GenericHolderNull.cs
var intHolder = new Number<int?>(null); // T is int?, which can be null
var stringHolder = new Number<string>("Hello"); // T is string
var objectHolder = new Number<object>(new object()); // T is object
var nullableHolder = new Number<int?>(5); // T is int?, with a value
Console.WriteLine(intHolder.Value); // Output: null
Console.WriteLine(stringHolder.Value); // Output: Hello
Console.WriteLine(objectHolder.Value); // Output: System.Object
Console.WriteLine(nullableHolder.Value); // Output: 5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment