¡@

Home 

c# Programming Glossary: groupby

c#: a method to count occurrences in a list

http://stackoverflow.com/questions/1139181/c-a-method-to-count-occurrences-in-a-list

... var l1 new List int 1 2 3 4 5 2 2 2 4 4 4 1 var g l1.GroupBy i i foreach var grp in g Console.WriteLine 0 1 grp.Key grp.Count.. a Func int TKey because my list is ints. So I'm telling GroupBy how to group my items. The Func takes a int and returns the..

How do I group data in an ASP.NET MVC View?

http://stackoverflow.com/questions/1160420/how-do-i-group-data-in-an-asp-net-mvc-view

If your view is strongly typed you can use the LINQ GroupBy extension method with nested foreach ul foreach var group in.. method with nested foreach ul foreach var group in Model.GroupBy item item.Category li Html.Encode group.Key ul foreach var item..

How to get distinct instance from a list by Lambda or LINQ

http://stackoverflow.com/questions/1183403/how-to-get-distinct-instance-from-a-list-by-lambda-or-linq

solution though. Instead of using Distinct you can use GroupBy . It goes like this var listDistinct list.GroupBy i i.value1.. can use GroupBy . It goes like this var listDistinct list.GroupBy i i.value1 key group group.First .ToArray Notice that I've passed.. .ToArray Notice that I've passed two functions to the GroupBy . The first is a key selector. The second gets only one item..

C# Reading a File Line By Line

http://stackoverflow.com/questions/1271225/c-sharp-reading-a-file-line-by-line

Where etc. Note that if you use OrderBy or the standard GroupBy it will have to buffer the data in memory ifyou need grouping..

ILookup<TKey, TVal> vs. IGrouping<TKey, TVal>

http://stackoverflow.com/questions/1337539/ilookuptkey-tval-vs-igroupingtkey-tval

IGrouping TKey TVal Which is equivalent to var q2 N.GroupBy n n.MyKey n n q2 is IEnumerable IGrouping TKey TVal Which looks.. is a do it now operation immediate execution whereas a GroupBy is deferred. As it happens with the way that pull LINQ works.. when you start pulling IGrouping s from the result of a GroupBy it has to read all the data anyway because you can't switch..

What is the point of Lookup<TKey, TElement>?

http://stackoverflow.com/questions/1403493/what-is-the-point-of-lookuptkey-telement

rather than just iterating over them all which is what GroupBy lets you do . For example you could take a load of .NET types..

Preserving order with LINQ

http://stackoverflow.com/questions/204505/preserving-order-with-linq

ThenBy ThenByDescending Redefines Order as side effect GroupBy The IGrouping objects are yielded in an order based on the order..

What guarantees are there on the run-time complexity (Big-O) of LINQ methods?

http://stackoverflow.com/questions/2799427/what-guarantees-are-there-on-the-run-time-complexity-big-o-of-linq-methods

.ThenBy and provide the same key to both I could see GroupBy and Join using either sorting or hashing. Which is it Contains.. so that this operation is O 1 instead of O N . Distinct GroupBy Join and I believe also the set aggregation methods Union Intersect..

F# Seq module implemented in C# for IEnumerable?

http://stackoverflow.com/questions/410717/f-seq-module-implemented-in-c-sharp-for-ienumerable

SelectMany IEnumerable TSource TResult s s Seq.distinct_by GroupBy keySelector .Select g g.First Seq.exists Any TSource Func TSource.. true and false respectively Which we can implement using GroupBy and a two element array as a poor man's tuple public static.. TSource source Func TSource bool predicate return source.GroupBy predicate .OrderByDescending g g.Key .ToArray Element 0 holds..

C# Using Activator.CreateInstance

http://stackoverflow.com/questions/5262693/c-sharp-using-activator-createinstance

method case Pivot return new Pivot originalData case GroupBy return new GroupBy originalData case Standard deviation return.. return new Pivot originalData case GroupBy return new GroupBy originalData case Standard deviation return new StandardDeviation..

Group by in LINQ

http://stackoverflow.com/questions/7325278/group-by-in-linq

g.ToList Or as a non query expression var results persons.GroupBy p p.PersonId p p.car key g new PersonId key Cars g.ToList Basically.. in this case present for the given key. For more on how GroupBy works see my Edulinq post on the topic . share improve this..

Distinct list of objects based on an arbitrary key in LINQ

http://stackoverflow.com/questions/742682/distinct-list-of-objects-based-on-an-arbitrary-key-in-linq

based on id . The best I could come up with is list list.GroupBy i i.id .Select g g.First .ToList Is there a nicer better quicker.. Using the Distinct method is about 4x faster than using GroupBy in my informal tests. For 1 million Foo's my test has Distinct.. to make a unique array out of a non unique array where GroupBy takes about 3.4 seconds. My Distinct call looks like var unique..