In my code I am creating a List<> of the following class:
public class Calculations
{
public int Year { get; set; }
public double Payment { get; set; }
public double AnnualInterest { get; set; }
public double AnnualPrincipalSplit { get; set; }
public double NLVBalance { get; set; }
public double apportionedValue { get; set; }
public double OpenMarketValue { get; set; }
public double NotionalLoan { get; set; }
public double ResidencyFee { get; set; }
public double BalanceOfShare { get; set; }
public double TotalShareOwnedOutright { get; set; }
public double TotalEquity { get; set; }
}
The list holds data which represents the term of the investment (for example over 30 years, there would be 30 items in the list)
I have a variable called globalReviewPeriod, which is a integer, and this is used to define when the data in the list should be aggregated upon (For example, if the globalReviewPeriod was 5, and the term of the investment was 30 years, then data would need to be aggregated upon in years 5, 10, 15, 20, 25, and 30).
The aggregation itself is pretty straight forward, its just the cumulative values of the data contained in the class.
However I am struggling with the logic on how I could aggregate the data, given the logic I have defined above (i.e over the review periods).
Any pointers would be gratefully received.
Use the overload of
Wherethat allows you to filter based on index:From the documentation, the lambda function is used as follows:
Note that the above code will always include the first item, as this has index 0 which is divisible by every number. You may wish to use
(index + 1)instead ofindexif you want to use 1-based indexing where the first element has index 1.