Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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


Please Help Members By Posting Answers For Below Questions

Why does dllimport not work for me?

1051


Do loops c#?

904


What is stringreader in c#?

889


What is an inheritance ?Give an example in which inheritance is used?

1047


Why c# is type safe?

941


When To use HashTable In C#

1034


What does type safety mean?

1080


What is the difference between continue and break statement?

969


List the 5 different access modifiers in c#?

931


Difference between StackPanel and RelativePanel ?

1032


How do you mark a method obsolete?

1017


What is tochararray in c#?

954


Is lazy thread safe c#?

884


What is the correct way of declaring an xml namespace?

828


What is the difference between const and readonly in c#.net?

951