snipt

Ctrl+h for KB shortcuts

C#

Modify one property of LINQ list

1
2
3
4
return customers.Select(i => {
    i.IsVip = DetermineVip(i.Score);
    return i;
}).ToList();
https://snipt.net/embed/a69d65d6c796e3fbf8596bdb09ba5f05/
/raw/a69d65d6c796e3fbf8596bdb09ba5f05/
a69d65d6c796e3fbf8596bdb09ba5f05
csharp
C#
4
2019-08-25T08:54:44
True
False
False
Mar 27, 2014 at 01:33 PM
/api/public/snipt/125309/
modify-one-property-of-linq-list
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="k">return</span> <span class="n">customers</span><span class="p">.</span><span class="n">Select</span><span class="p">(</span><span class="n">i</span> <span class="p">=&gt;</span> <span class="p">{</span> </span><span id="L-2"><a name="L-2"></a> <span class="n">i</span><span class="p">.</span><span class="n">IsVip</span> <span class="p">=</span> <span class="n">DetermineVip</span><span class="p">(</span><span class="n">i</span><span class="p">.</span><span class="n">Score</span><span class="p">);</span> </span><span id="L-3"><a name="L-3"></a> <span class="k">return</span> <span class="n">i</span><span class="p">;</span> </span><span id="L-4"><a name="L-4"></a><span class="p">}).</span><span class="n">ToList</span><span class="p">();</span> </span></pre></div> </td></tr></table>
C#, LINQ