if (user?.Identity?.IsAuthenticated ?? false)这几个问号分别都代表啥意思?
if (user?.Identity?.IsAuthenticated ?? false)这几个问号分别都代表啥意思?
0
悬赏园豆:5
[已解决问题]
浏览: 229次
解决于 2018-05-16 13:27
var user = HttpContext.User; if (user?.Identity?.IsAuthenticated ?? false) { } else { }
如题,求解。
最佳答案
1
?
如果不为null,执行其后的方法;??
如果为null,返回其后的值。
<div id="answer_option_226950">
<div class="qclear">
<div class="lf green">
收获园豆:<span class="red">5</span>
</div>
<div class="answer_author">
<a class="bluelink linkanswercommenttiny" aid="226950" id="link_answercomment_226950" onclick="showCommentMarkdownEditor('link_answercomment_226950', 0)" href="javascript:void(0);">回复</a>
<span class="v-split">|</span>
<a href="/u/dudu/" class="bluelink">dudu</a>
<span class="v-split">|</span>
<a class="graylink" href="/q/faq#qt">高人七级</a>
<span class="v-split">|</span>园豆:41494
<span class="v-split">|</span>
2018-05-16 10:32
</div>
</div>
</div>
<div class="q_answercomm" id="q_answercomm_226950">
</div>
其他回答(1)
0
等价于
bool isNull; if (user != null) { if (user.Identity != null) { if (user.Identity.IsAuthenticated != null) { isNull = user.Identity.IsAuthenticated; } } } isNull = false; if (isNull) {} </span></pre>
<div id="answer_option_226955">
</div>
<div class="q_answercomm qclear" id="q_answercomm_226955">
</div>
<div id="google_ad_bottom">
<script type="text/javascript">
var googletag = googletag || {};
googletag.cmd = googletag.cmd || [];
(function () {
var gads = document.createElement('script');
gads.async = true;
gads.type = 'text/javascript';
var useSSL = 'https:' == document.location.protocol;
gads.src = (useSSL ? 'https:' : 'http:') +
'//www.googletagservices.com/tag/js/gpt.js';
var node = document.getElementsByTagName('script')[0];
node.parentNode.insertBefore(gads, node);
})();
</script>
<script type="text/javascript">
googletag.cmd.push(function () {
googletag.defineSlot('/1090369/cnblogs_question_Q2', [728, 90], 'div-gpt-ad-1436511848662-0').addService(googletag.pubads());
googletag.pubads().enableSingleRequest();
googletag.pubads().collapseEmptyDivs();
googletag.enableServices();
});
</script>
<!-- /1090369/cnblogs_question_Q2 -->
<div id="div-gpt-ad-1436511848662-0" style="height:90px; width:728px;" data-google-query-id="CPeVmvWlrOMCFQcaKgodbM8C7w">
<div id="google_ads_iframe_/1090369/cnblogs_question_Q2_0__container__" style="border: 0pt none;"><iframe id="google_ads_iframe_/1090369/cnblogs_question_Q2_0" title="3rd party ad content" name="google_ads_iframe_/1090369/cnblogs_question_Q2_0" width="728" height="90" scrolling="no" marginwidth="0" marginheight="0" frameborder="0" srcdoc="" style="border: 0px; vertical-align: bottom;" data-google-container-id="1" data-load-complete="true"></iframe></div></div>
</div>
</div>
牛逼的写法,谢谢dudu,xiexie演员。
– 屌丝大叔的笔记 1年前 回复