cnblogs/dcrenl/C#中的另类语法.html

15 lines
648 B
HTML
Raw Permalink Normal View History

2024-09-24 12:43:01 +08:00
<div id="sina_keyword_ad_area2" class="articalContent ">
<div>一、.net中return的另类写法</div>
<div>不知道是从3.5还是从4.0开始C#语法中的return有了新的写法示例如下</div>
<div>public string functionDemo()</div>
<div>{</div>
<div>&nbsp; &nbsp; &nbsp; string s;</div>
<div>&nbsp; &nbsp; &nbsp; s = null;</div>
<div>&nbsp; &nbsp; &nbsp; return s ?? (s ="aaa");</div>
<div>}&nbsp;</div>
<div>此写法类似我们以前的&ldquo;return s== null ? "" : "aaaa";&rdquo;其实是相同的。对于经常写数据库开发的人来说有福了。</div>
<div>&nbsp;</div>
<div>&nbsp;</div>
</div>
<p>&nbsp;</p>