This blog is moved to
http://amalhashim.wordpress.com

Saturday, January 10, 2009

New in C# 3.0 - ?? Operator

The ?? Operator return the left hand operand if it is not null. Else it will return the right hand operand.

if(testObject == null)
{
testObject = new TestObject();
}

return testObject;

The above code can be represented in the following one liner

return testObject ?? new TestObject();

1 comment: