59
1
using System;
2
using System.Collections.Generic;
3
using System.Linq;
4
5
public class Program
6
{
7
public static void Main()
8
{
9
List<Investment> investments = new List<Investment>
10
{
11
new Investment { TransactionID = 1, InvestorID = 1, Date = new DateTime(2023, 1, 1), Amount = 1000m, ReturnPercentage = 0.05 },
12
new Investment { TransactionID = 2, InvestorID = 1, Date = new DateTime(2023, 2, 1), Amount = -500m, ReturnPercentage = 0.04 }, // A withdrawal
13
new Investment { TransactionID = 3, InvestorID = 2, Date = new DateTime(2023, 1, 15), Amount = 2000m, ReturnPercentage = 0.06 },
14
new Investment { TransactionID = 4, InvestorID = 2, Date = new DateTime(2023, 3, 1), Amount = 1500m, ReturnPercentage = 0.07 },
15
new Investment { TransactionID = 5, InvestorID = 3, Date = new DateTime(2023, 2, 20), Amount = 500m, ReturnPercentage = 0.05 }
16
};
17
18
// Step 1: Calculate the net investment for each investor
19
var netInvestments = investments
20
.GroupBy(i => i.InvestorID)
21
.Select(g => new
22
{
23
InvestorID = g.Key,
24
NetInvestment = g.Sum(i => i.Amount)
Cached Result
06/05/2023 09:22:00
05/29/2015 05:50:06
05/29/2015 05:50:00
06/30/2023 15:30:00
05/29/2015 05:50:06
05/29/2015 05:50:00
06/30/2023 15:30:00