how to count object in a collection

  • Thread starter Thread starter Tony Johansson
  • Start date Start date
T

Tony Johansson

Hello!

I don't have LINQ at the moment.

I have a collection with Products object
A Product have the following fields in this order.
string Name;
int ProductNumber;
int numberInstock;
int month; //The month this product was sold
int year; //The year this product was sold.

I just wonder if there are good way to count every object that have the
following criteria.
1.Some objects in the collection have year = 2009
2. Perform a group by on month so you will get how many objects you have for
each month.


//Tony
 
I don't have LINQ at the moment.

Well, that's easy to fix, even if you're on 2.0:

http://www.albahari.com/nutshell/linqbridge.aspx

If you're using VS2008 (but target .NET 2.0 rather than 3.5), then you
just reference this assembly, and then use LINQ normally. If you use
VS2005, then you'll have to call extension methods as static, and use
anonymous delegates instead of lambdas (and, of course, cannot use
LINQ syntactic sugar), but all the functionality is there - including
group by/
 
Hello!

I have downloaded this LINQBridge.dll now but where should I put it.

//Tony


"Pavel Minaev" <[email protected]> skrev i meddelandet
I don't have LINQ at the moment.

Well, that's easy to fix, even if you're on 2.0:

http://www.albahari.com/nutshell/linqbridge.aspx

If you're using VS2008 (but target .NET 2.0 rather than 3.5), then you
just reference this assembly, and then use LINQ normally. If you use
VS2005, then you'll have to call extension methods as static, and use
anonymous delegates instead of lambdas (and, of course, cannot use
LINQ syntactic sugar), but all the functionality is there - including
group by/
 
I have downloaded this LINQBridge.dll now but where should I put it.

It's handled the same way as any third-party assembly - you need to
add a reference to it from your project, and not forget to
redistribute it with your application.
 
Back
Top