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 semaphore in c#?
What is the syntax for calling an overloaded constructor within a constructor?
Explain when should you call the garbage collector in .net?
List out two different types of errors in c#?
Is string a primitive data type in c#?
Are arrays value types or reference types?
What is a template class?
Define an assembly in .net?
What's new in c#?
What is collection class c#?
Which is faster list or dictionary in c#?
How many constructors can a class have in c#?
What is mvc firstordefault?
Define a partial class?
What are delegates?