How to extract first data from list with some condition using LINQ

  • Thread starter Thread starter Sudip_inn
  • Start date Start date
S

Sudip_inn

Guest
see this is my data

List<WeightageRowNumber> oWeightageRowNumber = new List<WeightageRowNumber>
{
new WeightageRowNumber { Section = "Consensus Model", Lineitem = "Net Revenue",Broker="BW",Weightage=1,RowNumber=1},
new WeightageRowNumber { Section = "Consensus Model", Lineitem = "Net Revenue",Broker="3P-1",Weightage=1,RowNumber=2},

new WeightageRowNumber { Section = "Consensus Model", Lineitem = "Net Revenue",Broker="",Weightage=2,RowNumber=3},

new WeightageRowNumber { Section = "Consensus Model", Lineitem = "Net Revenue",Broker="",Weightage=3,RowNumber=4},
new WeightageRowNumber { Section = "Consensus Model", Lineitem = "Net Revenue",Broker="",Weightage=3,RowNumber=5},

new WeightageRowNumber { Section = "Consensus Model", Lineitem = "Cost of Revenue",Broker="BW",Weightage=1,RowNumber=6},
new WeightageRowNumber { Section = "Consensus Model", Lineitem = "Cost of Revenue",Broker="3P-1",Weightage=1,RowNumber=7},

new WeightageRowNumber { Section = "Consensus Model", Lineitem = "Cost of Revenue",Broker="",Weightage=2,RowNumber=8},

new WeightageRowNumber { Section = "Consensus Model", Lineitem = "Cost of Revenue",Broker="",Weightage=3,RowNumber=9},
new WeightageRowNumber { Section = "Consensus Model", Lineitem = "Cost of Revenue",Broker="",Weightage=3,RowNumber=10},

new WeightageRowNumber { Section = "Key Financials", Lineitem = "Quick Ratio",Broker="BW",Weightage=1,RowNumber=11},
new WeightageRowNumber { Section = "Key Financials", Lineitem = "Quick Ratio",Broker="3P-1",Weightage=1,RowNumber=12},

new WeightageRowNumber { Section = "Key Financials", Lineitem = "Quick Ratio",Broker="",Weightage=2,RowNumber=13},

new WeightageRowNumber { Section = "Key Financials", Lineitem = "Quick Ratio",Broker="",Weightage=3,RowNumber=14},
new WeightageRowNumber { Section = "Key Financials", Lineitem = "Quick Ratio",Broker="",Weightage=3,RowNumber=15},

};



i want to extract first data from above list whose Weightage is 1.

var _data = oWeightageRowNumber.Where(x => x.Weightage == 1).FirstOrDefault();

the above code is not give right data.

output should return these data

Section = "Consensus Model", Lineitem = "Net Revenue",Broker="BW",Weightage=1,RowNumber=1

Section = "Consensus Model", Lineitem = "Cost of Revenue",Broker="BW",Weightage=1,RowNumber=6

Section = "Key Financials", Lineitem = "Quick Ratio",Broker="BW",Weightage=1,RowNumber=11

the above 3 records will be my output whose weitage is one. so tell me what will be my LINQ code. thanks

Continue reading...
 
Back
Top