I want to convert these two "ugly" for loops to a LINQ expression. Can anyone help me out? I am pretty new to LINQ. thanks in advance!
foreach (Edge edge in distinctEdge)
{
var c = 0;
foreach(Edge e in EdgeList)
{
if(e.target == edge.target && e.source == edge.source)
{
c++;
}
}
edge.value = c;
}
Use ReSharper:
foreach (var edge in distinctEdge)
{
edge.value = EdgeList.Count(e => e.target == edge.target && e.source == edge.source);
}
Something easy to read and understand
var value=(from edge in distinctEdge
join e in EdgeList
on edge.Target equals e.Target
and e.source equals edge.source
select edge ).Count();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With