I've retrieved a list from the DB that contains colors. Then, I filtered them in the UI to count how many I have from each color.
OutModelListCnt.RED_CNT = OutModelList.Filter(p => p.COLORS.Equals("RED")).Count.ToString();
OutModelListCnt.GREEN_CNT = OutModelList.Filter(p => p.COLORS.Equals("GREEN")).Count.ToString();
OutModelListCnt.BLUE_CNT = OutModelList.Filter(p => p.COLORS.Equals("BLUE")).Count.ToString();
OutModelListCnt.WHITE_CNT = OutModelList.Filter(p => p.COLORS.Equals("WHITE")).Count.ToString();
OutModelListCnt.PINK_CNT = OutModelList.Filter(p => p.COLORS.Equals("PINK")).Count.ToString();
OutModelListCnt.BLACK_CNT = OutModelList.Filter(p => p.COLORS.Equals("BLACK")).Count.ToString();
This is working perfectly fine. It retrieves how many I have from each:
RED = 3
GREEN = 2
BLUE = 7
WHITE = 4
PINK = 0
BLACK = 8
My question is how can I get the total count of the RED+GREEN+BLUE together, since I'm filtering the list in the UI and not from the DB.
一个简单的Linq查询,使用带有多个OR(||)条件的Where运算符
var count = OutModelList.Where(c => c.COLORS.Equals("RED") || c => c.COLORS.Equals("GREEN") || c => c.COLORS.Equals("BLUE")).Count()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.