Created
August 11, 2014 02:42
-
-
Save elleryq/7974b237181693243d43 to your computer and use it in GitHub Desktop.
Try C# Nullable. The code can be paste in LINQPad and run. If you want to run in Visual Studio or other IDE, you need to rewrite it.
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
void Main() | |
{ | |
String s = null; | |
Console.WriteLine("s is {0}", s ?? "Null"); | |
Animal animal = null; | |
Console.WriteLine("Animal is {0}", animal ?? new Animal()); | |
Nullable<int> i = null; | |
Console.WriteLine("i is {0}", i ?? default(int)); | |
Console.WriteLine("i is {0}", i.GetValueOrDefault()); | |
} | |
// Define other methods and classes here | |
class Animal { | |
private string _name = "Animal"; | |
public Animal() { | |
} | |
public Animal(String name) { | |
_name = name; | |
} | |
override | |
public String ToString() { | |
return _name; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment