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
Why do we use ienumerable in c#?
What is difference between abstract class and interface in c#?
What's the difference between abstraction and encapsulation?
What is an assembly in dotnet?
In which order the destructor is called for an inherited class?
What is form feed and carriage return?
Can we create instance of private class in c#?
What is a must for multitasking
How does bitwise xor work?
What is default value of bool in c#?
What are fields in c#?
What is file extension of webservices?
What is delegates in c# and uses of delegates?
What is protected internal modifier in C#?
Explane each and every methods of nterface Queue? Explain About performance issues on retrieving records