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 does dllimport not work for me?
Do loops c#?
What is stringreader in c#?
What is an inheritance ?Give an example in which inheritance is used?
Why c# is type safe?
When To use HashTable In C#
What does type safety mean?
What is the difference between continue and break statement?
List the 5 different access modifiers in c#?
Difference between StackPanel and RelativePanel ?
How do you mark a method obsolete?
What is tochararray in c#?
Is lazy thread safe c#?
What is the correct way of declaring an xml namespace?
What is the difference between const and readonly in c#.net?