Skip to content

Instantly share code, notes, and snippets.

@elleryq
Created August 11, 2014 02:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elleryq/7974b237181693243d43 to your computer and use it in GitHub Desktop.
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.
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