I have a list, A
List<int> A = new List<int>() {1,2,3,4,5};
I also have a bool variable S. I want to copy A into another list using LINQ, with a condition: if S is false then copy the negative value of each element in A (e.g. {-1,-2..}) else it will be the same, like {1,2..}
If I understand your question correctly, that’s indeed possible:
Or, using a lambda expression:
You can even do that without using the ternary conditional operator: