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 / rajesh kardile

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 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is asp net c#?

582


How jit (just in time) works?

587


What are the classes contained in a single .NET DLL ?

588


What is a data set in c#?

584


What language do desktop applications use?

558






What does void do in c#?

628


What is dynamic object in c#?

591


What is oledb in c#?

607


How many aware interfaces are there?

554


How do you concatenate in c#?

564


Why is hashset faster?

571


Why main is static in c#?

641


When a switch is said to be congested?

655


What does console readline do?

550


What is an assembly loader?

587