Hi Friends,
I need to find distinct
names
from a list and it should return
List<Contribution>
Below is my list
List<LinearGrowth> lstlg = new List<LinearGrowth>()
{ new LinearGrowth {year=2016,endingvalue=23.5, cahflow=new List<Contribution>()
{new Contribution{id=1,name="Salary"},
new Contribution{id=2,name="Rent"},
}},
new LinearGrowth{year=2017,endingvalue=25.0,cahflow=new List<Contribution>()
{new Contribution{id=1,name="Salary"},
new Contribution{id=2,name="Rent"},
new Contribution{id=3,name="interest"},
}},
new LinearGrowth{year=2018,endingvalue=29,cahflow=new List<Contribution>()
{new Contribution{id=1,name="Salary"},
new Contribution{id=2,name="Rent"},
new Contribution{id=4,name="FD"},
new Contribution{id=5,name="MutualFund"},
}},
};
Result Should be
1 salary
2 Rent
3 Interest
4 FD
5 Mutual Fund
Please help
What I have tried:
var res = lstlg.SelectMany(cf => cf.cahflow)
.Select(d => new Contribution { id = d.id, name = d.name, })
.Distinct();