Monthly Archive for August, 2007

Short, Shorter, Shortest

Three C# code snippets with the same meaning…

Variant 1: Using a full if/else clause
MyClass result;
if (
input!= null)
result= input;
else
result= new MyClass();

Variant 2: Using the ?/: conditional operator
MyClass
result = input != null ? input : new MyClass();

Variant 3: Using the ?? operator
MyClass result = input ?? new MyClass();

I did not know about the ?? operator, until Resharper 3 suggested to use variant 3 instead of variant 2 :-)

0.5 liter = 2 x 0.25 liter

What does Coca-Cola want to say us with it’s calculation!? Yes…it may be quite difficult to find out, that half a liter is twice as big as a quarter-liter! ;-)

coke-calc.jpg

I guess, Google is not the only one who can solve 2 x 0.25 liter.