c# - Can I use the ? : syntax to decide what my method returns -



c# - Can I use the ? : syntax to decide what my method returns -

i have action method in webapi executes sql:

var sql = @"update usertestquestion set answergridresponses = @answergridresponses, answered = 1 usertestquestionid = @usertestquestionid , userid = @userid;"; var parameters = new sqlparameter[] { new sqlparameter("@createdby", createdby), new sqlparameter("@answergridresponses", answergridresponses), new sqlparameter("@testquestionid", testquestionid) }; var rc = await db.database.executesqlcommandasync(sql, parameters); if (rc > 0) { homecoming ok(rc); } else { homecoming badrequest(); }

it's understanding executesqlcommandasync homecoming number indicate how many rows changed. added check rc > 0.

is there way without need of {}. thinking of using ? : operators, think these work setting value , not returns using.

you can want do.

return (rc > 0) ? ok(rc) : badrequest();

although may argue using if/else cleaner. don't need curly braces, can do:

if (rc > 0) homecoming ok(rc); else homecoming badrequest();

c# asp.net-web-api return-value null-coalescing-operator

Comments

Popular posts from this blog

maven fortify plugin : Unable to load build session with ID XXXXX .. See log file for more details -

c# - Primavera WebServices does not return any data -

android - Display emoji panel with genymotion - keyboard/touch input? -