I have following statement
Select(g => new AssembledPartsDTO
{
..
..
References = g.SelectMany(entry => entry.References).OrderBy(t => t).ToList()
..
..
}
How I can add if References.count == 0 than Add("??")
to References
?
Use ?: Operator
References.count > 0 ? References : new List<string>(){"??"}
How about that
Use a ternary operator in your LINQ expression.
You could do something like this;
References = (g.SelectMany(entry => entry.References).Count() == 0)
? g.SelectMany(entry => entry.References).OrderBy(t => t).ToList() : null;
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