C#linq calculate the total number of bars and repeat the notation

Source: Internet
Author: User
Tags repetition

One, in the actual demand we will exist to select a set, and then we need to use some of the collection of fields to calculate the repetition, and statistical repetition of the number, then we can be used to filter and repeat LINQ.

Two, the following code:

usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSystem.Threading.Tasks;namespacebao{classProgram {Static voidMain (string[] args) {List<Demo> result =NewList<demo>(); Result. ADD (NewDemo () {Name="1", Pro="1", Code="1"            }); Result. ADD (NewDemo () {Name="1", Pro="1", Code="1"            }); Result. ADD (NewDemo () {Name="2", Pro="2", Code="3"            }); Result. ADD (NewDemo () {Name="3", Pro="3", Code="3"            }); Result. ADD (NewDemo () {Name="4", Pro="4", Code="4"            }); varTest = fromAinchresultSelect New{schoolname=A.name, Province=A.pro, Schoolcode=A.code, Counts= ( fromTinchresultwhereT.name = = A.name && T.pro = = A.pro && T.code = =A.code Group T byNew{Name = t.name, Pro = T.pro, Code =T.code} into GSelect New{counts =G.count ()}).            FirstOrDefault (). counts}; varTTT =test.            ToList (); varAAA =TTT. Distinct (). ToList ();        }    }     Public classDemo { Public stringCode {Get;Set; }  Public stringName {Get;Set; }  Public stringPro {Get;Set; }  Public intCounts {Get;Set; } }}

C#linq calculate the total number of bars and repeat the notation

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.