f i give input like 1,1,4,5,6,1,2,5,4,1,2, then output
should be like : 1-4, 2-2, 4-2, 5-1, 6-1 which means 1
occurs 4 times, 2 occurs 2 times like so.

Answer Posted / amitabh dubey

In C# 3.0 with Linq here how you will do

int[] intArray = { 1, 1, 4, 5, 6, 1, 2, 5, 4, 1, 2 };

var groups = from g in intArray
orderby g
group g by g;

StringBuilder stringBuilder = new StringBuilder();

foreach (var g in groups)
stringBuilder.Append(g.Key + "-" + g.Count() + ",");

Console.WriteLine(stringBuilder.ToString());

Is This Answer Correct ?    1 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is an icollection in c#?

575


What's c# ?

664


What do you mean by stack and heap in c#?

557


Why do we need interface in c#?

582


What is the difference between yield and return?

537






What is a byte in c#?

637


What is exe file in c#?

557


What is overloading in c#?

562


How will you deploy the dll file in gac?

573


Why do we use dictionary in c#?

577


What is the use of the dispose method in C# ?

609


How to install or uninstall a windows service?

645


What is the use of expression tree in c#?

549


How big is a 64 bit integer?

582


What are the different ways of method can be overloaded?

553