score:0
class class1
{
public string produce { get; set; }
public string companyname { get; set; }
public string link { get; set; }
}
private void button3_click(object sender, eventargs e)
{
list<class1> lst = new list<class1>();
lst.add(new class1() { produce = "a", companyname="b", link="c" });
lst.add(new class1() { produce = "a", companyname = "b", link = "c" });
lst.add(new class1() { produce = "a", companyname = "d", link = "c" });
lst.add(new class1() { produce = "e", companyname = "b", link = "c" });
var result = lst.groupby(x => x.produce + x.companyname + x.link).select(g => new { produce = g.first().produce,
company = g.first().companyname,
link = g.first().link,
count = g.count()
}).tolist();
}
Source: stackoverflow.com
Related Query
- Getting count of BsonDocuments using LINQ and placing results in a new list
- PagedList using LINQ Skip and Take, but show paging using Count of results
- Best way to join 3 lists and count how many times an ID is in the list using linq
- List Categories and it's count of products with LinQ using Lambda or classic expressions
- Grouping List elements and map to new model using Linq
- using LINQ to separate a list element and inserting the results back to list
- Return a List with multiple results using LINQ and EF
- Getting the time difference using LINQ from a list of TimeSpans and parsing the time in as only minutes and seconds
- add a new column to list using linq and entity?
- Getting a total count and sum using linq lambda
- Getting Count of the first list from joined two lists using Linq C#
- Getting rid of outer foreach loop using linq or lambda and ensuring no duplicates are added to list
- Using Linq and C#, how would I categorize a list of list and getting empty categories?
- Using a list of Json results as parameters for a mvc actionresult, to return objects from database with Linq and Lambda
- Access two indexes in a list and create a list of new objects using Linq
- using Linq to iterate over an array and create a new List of objects?
- Match a comma delimited string to an integer list using linq and return the new objects
- getting values of DataTable column and putting it into new datatable C# using LINQ
- Convert list to dictionary using linq and not worrying about duplicates
- Using Linq to group a list of objects into a new grouped list of list of objects
- Using GroupBy, Count and Sum in LINQ Lambda Expressions
- Return list using select new in LINQ
- compare two list and return not matching items using linq
- Use LINQ and C# to make a new List from an old List
- How to update an element with a List using LINQ and C#
- Linq to SQL using group By, and order by count
- Count values in Dictionary using LINQ and LINQ extensions
- Count Occurrences of an Item in a List using LINQ
- Sort a list and all its nested objects using LINQ
- Convert a list to a dictionary and sum up values using linq
More Query from same tag
- Linq: Using ElementAt on a database
- How to use the LINQ where expression?
- Linq search text using 'and' operator in joined fields from different tables
- How to make calculation on time intervals?
- Group By anonymous type is comparing by ref not by attributes
- Dynamically create anonymous object from list values c#
- transforming to linq
- Is it possible to prevent LINQ from using variables in queries and instead use string literals?
- What is the equivalent LINQ to SQL query expression of this SQL statement?
- optimising linq queries to incres
- How to use group by on a DataTable in LINQ?
- "Operation is not valid due to the current state of the object." Exception, when I want to retrieve Items
- How select max of string in linq to nhibernate
- Linq: Select Most Recent Record of Each Group
- How to build join string by expression tree
- Getting a nested object in C# from Json from a list by specifying a certain attribute
- XML with subquerys using LINQ
- How do I query sysobjects with linq?
- How to do Order By with null at the end
- Caching in Entity Framework Extended and Expression
- Compare lists to retrieve object properties that don't match
- Does .AsQueryable() stop IEnumerable from pulling all into memory?
- LINQ way to get items between two indexes in a List
- What Do Multiple Return Statements in a Linq.Select() Do?
- Logic Evaluator in c# (Evaluate Logical (&& ,|| ) expressions)
- NHibernate IQueryable.SingleOrDefault in subquery. Use function predicate without executing
- Querying multiple parameters using Linq with Marten in Visual Studio
- How To Get All Tweets on Hashtag using LinqToTwitter
- Generic list in an interface
- merge 2 collections, prefer items of the second collection