Created
April 27, 2012 12:55
-
-
Save TryJSIL/2508969 to your computer and use it in GitHub Desktop.
Nullables
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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