c# - groupby count and percentage -
is there simple way show percentage of total within linq groupby
?
i have:
private static object getpageusers(ienumerable<pagehit> getpagelog) { return getpagelog .groupby(g => g.userid) .select(x => new { user = getuserfname(x.key.tostring()), numberofhits = x.count(), percentage = x.count() / total }) .orderbydescending(o => o.numberofhits); }
in line percentage = x.count() / total
how total?
getpagelog ienumerable, has no count property. should have count()
extension method.
you using:
private static object getpageusers(ienumerable<pagehit> getpagelog) { return getpagelog .groupby(g => g.userid) .select(x => new { user = getuserfname(x.key.tostring()), numberofhits = x.count(), percentage = (100 * x.count()) / getpagelog.count() + "%" }) .orderbydescending(o => o.numberofhits); }
Comments
Post a Comment