Question in linq statement

Bibulous

New member
Joined
Nov 4, 2024
Messages
1
Programming Experience
Beginner
Hi,

How would I return a List<Transaction> like this? isPutCall(Transaction) is just a boolean that returns true or false.

What I am trying to do is get a List<Transaction> from "allTransactions" that match the put/call criteria, but the first line errors. I am new to C# and I see many examples around linq statements, and think I am missing a small addition below?

C#:
 public List<Transaction> FilterTransactions(List<Transaction> allTransactions)
        {
            List<Transaction> options = allTransactions.Select(t => isPutCall(t));

            return options;
}
 
Firstly, you need to call Where rather than Select. The former is how you filter, i.e. get some complete items from a source list. The latter is used to protect, i.e. get all partial items from a source list. Secondly, you need to call ToList on that result to realise the query and create a List.
 
Back
Top Bottom