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 icollection in c#?
What is the difference between struct and class c#?
What is main thread in c#?
Explain the functionalities of satellite assembly?
What is equal c#?
How many bytes is a char c#?
Is null empty or whitespace c#?
How does insertion sort work?
What is msil, and why should developers need an appreciation of it if at all?
Explane each and every methods of nterface Queue? Explain About performance issues on retrieving records
What is the meaning of MSIL?
What are "class access modifiers" in C#?
Explain the mechanism of VB.NET/C# achieve polymorphism?
Why linq is having select clause at the end?
What is the use of return in c#?