I have a class with these properties:
public List<CommitmentItem<ITransaction, ITransactionItem>> CommitmentItems;
public List<CapitalCallCommitmentItem> CapitalCallCommitmentItems;
CapitalCallCommitmentItem
inherits CommitmentItem. I want the CapitalCallCommitmentItems
property to return all CommitmentItems
where the type is of CapitalCallCommitmentItem. So I tried this code:
get
{
return CommitmentItems
.Where(c => c.GetType() == typeof(CapitalCallCommitmentItem))
.Select(c => (CapitalCallCommitmentItem)c)
.ToList();
}
However, I get an error saying:
Error 1 Cannot convert type 'Models.CommitmentItem' to 'Models.CapitalCallCommitmentItem'
What's the right way to do this?