Skip to content

Instantly share code, notes, and snippets.

@TryJSIL
Created April 27, 2012 12:55
Show Gist options
  • Save TryJSIL/2508969 to your computer and use it in GitHub Desktop.
Save TryJSIL/2508969 to your computer and use it in GitHub Desktop.
Nullables
using System;
public static class Program {
public static void PrintNullable (int? i) {
if (i.HasValue)
Console.Write("{0} ", i.Value);
else
Console.Write("null ");
}
public static void Print2Nullables (int? a, int? b) {
PrintNullable(a);
PrintNullable(b);
Console.WriteLine();
}
public static void Print3Nullables (int? a, int? b, int? c) {
PrintNullable(a);
PrintNullable(b);
PrintNullable(c);
Console.WriteLine();
}
public static void Main(string[] args)
{
int? one = 1, two = 2, three = 3;
int? nul = null;
Print3Nullables(one, two, null);
Print2Nullables(one + one, one - one);
Print2Nullables(one + nul, one - nul);
Print2Nullables(nul + nul, nul - nul);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment