if statement - c# If Control in single row -
i using asp.net mvc view , in order utilize if command .
my code:
<div class="panel-body @(((objectmodellibrary.law)viewdata["currentlaw"]).laststatus == "" ? "collapse" : string.empty)"> my question above if control:
i want check
if ((objectmodellibrary.law)viewdata["currentlaw"]).laststatus == null || if ((objectmodellibrary.law)viewdata["currentlaw"]).laststatus == "" i want utilize ? "collapse" : else : string.empty)">
how can utilize if not null , if not "" in 1 row in code?
if you're checking whether string value either null or "" utilize isnullorempty:
string.isnullorempty(((objectmodellibrary.law)viewdata["currentlaw"]).laststatus) ? "collapse" : string.empty if want combine multiple conditions in conditional expression, can logical operators. example:
if (somecondition && someothercondition) this require both conditions true. (if utilize || operator instead require at to the lowest degree one status true.)
so in ?: operator might like:
(somecondition || someothercondition) ? somevalue : someothervalue logical segments of conditional expressions can grouped parentheses, can include many like:
(condition1 || (condition2 && condition3)) ? somevalue : someothervalue technically can build conditions , other expressions big you'd like, though of course of study code readability , maintainability becomes issue pretty quickly. extracting logic separate methods helps maintain code more organized.
c# if-statement model-view-controller
No comments:
Post a Comment