Tech
Forums
Jobs
Books
Events
Interviews
Live
More
Learn
Training
Career
Members
Videos
News
Blogs
Login
Sign Up
Ask Question
2
Reply
Group list by last 2 months and count its distinct items
Lance Kidd
Mar 5 2017 10:34 AM
338
Reply
Hi to all. Good day. I want to group a list by last 2 months and count how many products are their in every month and also count distinct category for every product sold in each month
I have a list. It contains a class named ProductTransaction.
List<ProductTransaction> productList = new List<ProductTransaction>();
class ProductTransaction
{
string product;
DateTime date_sold;
string category;
}
productList.Add(new ProductTransaction () {product="sword", date_sold=03/05/2017,category="weapons"});
productList.Add(new ProductTransaction() {product="sword2", date_sold=03/01/2017,category="weapons"});
productList.Add(new ProductTransaction() {product="potion", date_sold=02/05/2017,category="life"});
productList.Add(new ProductTransaction() {product="jacket", date_sold=02/03/2017,category="clothing"});
productList.Add(new ProductTransaction() {product="jacketofBear", date_sold=02/01/2017,category="clothing"});
I want to achieve a data like below.Please see attached image file
Month productCount categoryCount
March 2 1
February 3 2
Thank you and GodBless
Upload Source Code
Select only zip and rar file.
Post
Reset
Cancel
Answers (
2
)
Next Recommended Forum
array concept stack dynamic static fixed heap-dynamic fixed
Hackerrank Test code doesnt compile