Click here to Skip to main content
15,124,736 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
let value2 = Grp.Count(x => x.Column1 <= 2 && x.Column2== "studentName") * 100 / Grp.Count(x => x.Column2== "studentName")




In this Statement some times the divider is Null so it pass NaN value how can I replace the divider from 0 to 1.

What I have tried:

let value2 = Grp.Count(x => x.Column1 <= 2 && x.Column2== "studentName") * 100 / Grp.Count(x => x.Column2== "studentName")



In this Statement some times the divider is Null so it pass NaN value how can I replace the divider from 0 to 1.
Posted
Updated 16-Mar-16 23:18pm
Comments
Sinisa Hajnal 17-Mar-16 5:56am
   
write it in two lines and check for 0. If you call first or default, you would get 0 again...maybe someone with more Linq mojo can find a workaround, but I think it would be better to write it in more lines.

Either with an extension method like shown when following the link of solution 1 or like this:
C#
Math.Max(Grp.Count(x => x.Column2== "studentName"), 1)
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900