C#:缩短代码(Nullable Object,Return Property或String.Empty)

Ale*_*lex 0 c#

我想知道是否有人可以为此代码提出缩短版本:

MyObject theObject = ObjectCollection.GrabAnObject();
if (theObject == null) return String.Empty;
else return theObject.myProperty;
Run Code Online (Sandbox Code Playgroud)

谢谢!

Ars*_*yan 8

MyObject theObject = ObjectCollection.GrabAnObject();
return theObject == null ? String.Empty : theObject.myProperty;
Run Code Online (Sandbox Code Playgroud)