Thursday, 15 April 2010

c# - What does this code with "?" and "??" mean? -



c# - What does this code with "?" and "??" mean? -

what syntax mean? i'm coding c# 4.0, when came piece of code.

_data = (serializationhelper.deserialize(request.form[_datakey]) ? tempdata[_datakey] ?? new profiledata ()) profiledata;

if write if statements how then?

the compiler gives me error not writing : aswell more things needed?

looks missed ? there. suspect supposed read:

_data = (serializationhelper.deserialize(request.form[_datakey]) ?? tempdata[_datakey] ?? new profiledata() ) profiledata;

in c# operation a ?? b straight equivalent (a == null ? b : a), or if (a == null) homecoming b; homecoming a; if prefer.

so statement above equivalent to:

object tmp = serializationhelper.deserialize(request.form[_datakey]); if (tmp == null) { tmp = tempdata[_datakey]; if (tmp == null) _tmp = new profiledata(); } _data = tmp profiledata;

c# asp.net-mvc syntax operators

No comments:

Post a Comment