c# - Linq, from list of objects, create list of properties based on another property's value -
i need list of riseperiods bitpos > 2.
class bit { public int bitpos { get; set; } public int riseperiod { get; set; } } list<bit> databits;
i tried
ienumerable<int> rplist = databits .where(bit => bit.bitpos > 2) .select(bit => bit.riseperiod);
and
ienumerable<int> rplist = bit in databits bit.bitpos > 2 select bit.riseperiod
as other ways, each returns entire databits list instead of list of riseperiods. should simple - right?
thanks!
i've tried , seems working fine, suspected syntax , logic looks correct. try adding call tolist
make more clear when inspected list of integers. if not, there must else going on here. here's code suggest:
ienumerable<int> rplist = databits .where(bit => bit.bitpos > 2) .select(bit => bit.riseperiod) .tolist();
Comments
Post a Comment