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
What is an icollection in c#?
What's c# ?
What do you mean by stack and heap in c#?
Why do we need interface in c#?
What is the difference between yield and return?
What is a byte in c#?
What is exe file in c#?
What is overloading in c#?
How will you deploy the dll file in gac?
Why do we use dictionary in c#?
What is the use of the dispose method in C# ?
How to install or uninstall a windows service?
What is the use of expression tree in c#?
How big is a 64 bit integer?
What are the different ways of method can be overloaded?