Wednesday, October 23, 2013
Schrodinger's Cat: Wanted Dead AND Alive
If you don't know about Schrodinger's Cat you should.
The state of being alive can be represented by a boolean value. True or False. Alive or Not.
Structs have to have a value. So if I create a new bool, Cat.IsAlive, it takes the default bool value of false. Here's the code to prove it.
public class Cat{
public bool IsAlive{set; get;}
}
Cat SchrodingersCat = new Cat();
Console.WriteLine(SchrodingersCat.IsAlive);
output:
False
Poor kitty...
If you take the default bool he's always dead. The problem is before you open the box, you don't know whether the cat is alive or dead. Sometimes he survives...and is angry. You still want to use a bool. Just make it nullable.
public class Cat{
public bool? IsAlive{set; get;}
}
Cat SchrodingersCat = new Cat();
Console.WriteLine(SchrodingersCat.IsAlive);
output:
That's better. It looks empty. And it is...kind of. It's null. After you run Box.Open()the value will change to a good'ol true or false.
Before the box is opened the cat isn't alive or dead, it's just null.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment