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
What is serialization in .net?
If I want to override a method one of class A and in class b then how do you declare?
Which attribute is used in order that the method can be used as webservice?
Give examples for value types?
Different between method overriding and method overloading?
To catch any possible exception What is the C# syntax written ?
What is difference between list and dictionary in c#?
What is indexer c#?
Explain how to use an extender provider in the project.
what will be the output of the given below coding. using System; public class Exercise { static void OddNumbers(int a) { if (a >= 1) { Console.Write("{0}, ", a); a -= 2; OddNumbers(a); } } public static int Main() { const int Number = 9; Console.WriteLine("Odd Numbers"); OddNumbers(Number); Console.WriteLine(); return 0; } }
What is writeline in c#?
What is difference between private, protected, and public in C#?
What is asynccallback c#?
Explain About Global.asax
What are the fundamental oop concepts?