PC Review


Reply
Thread Tools Rate Thread

how to count object in a collection

 
 
Tony Johansson
Guest
Posts: n/a
 
      6th May 2009
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


 
Reply With Quote
 
 
 
 
sloan
Guest
Posts: n/a
 
      6th May 2009
Are you on the 2.0 framework?

http://www.scribd.com/doc/2057557/CTG-Articles-Generics


public ProductCollection : List<Product>
{
//yep, that's it
}


Read Ludwig's article. Create a "ProductFilter". Use the filter with the
ProductCollection.FindAll method.
Then you'll have a count.



"Tony Johansson" <(E-Mail Removed)> wrote in message
news:KkfMl.8512$(E-Mail Removed)...
> 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
>
>



 
Reply With Quote
 
Tony Johansson
Guest
Posts: n/a
 
      6th May 2009
yes!!

VS05

//Tony

"sloan" <(E-Mail Removed)> skrev i meddelandet
news:(E-Mail Removed)...
> Are you on the 2.0 framework?
>
> http://www.scribd.com/doc/2057557/CTG-Articles-Generics
>
>
> public ProductCollection : List<Product>
> {
> //yep, that's it
> }
>
>
> Read Ludwig's article. Create a "ProductFilter". Use the filter with the
> ProductCollection.FindAll method.
> Then you'll have a count.
>
>
>
> "Tony Johansson" <(E-Mail Removed)> wrote in message
> news:KkfMl.8512$(E-Mail Removed)...
>> 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
>>
>>

>
>



 
Reply With Quote
 
Pavel Minaev
Guest
Posts: n/a
 
      6th May 2009
On May 6, 5:25*am, "Tony Johansson" <johansson.anders...@telia.com>
wrote:
> 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/
 
Reply With Quote
 
Tony Johansson
Guest
Posts: n/a
 
      6th May 2009
Hello!

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

//Tony


"Pavel Minaev" <(E-Mail Removed)> skrev i meddelandet
news:d9a69169-3141-40e6-b25e-(E-Mail Removed)...
On May 6, 5:25 am, "Tony Johansson" <johansson.anders...@telia.com>
wrote:
> 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/


 
Reply With Quote
 
Pavel Minaev
Guest
Posts: n/a
 
      6th May 2009
On May 6, 9:47*am, "Tony Johansson" <johansson.anders...@telia.com>
wrote:
> 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.
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Adding class object to collection repeats same object through collection? Erazmus Microsoft Excel Programming 2 17th Sep 2007 04:35 AM
Collection problems (create Collection object, add data to collection, bind collection to datagrid) Øyvind Isaksen Microsoft ASP .NET 1 18th May 2007 10:24 AM
Collection problems (create Collection object, add data to collection, bind collection to datagrid) Øyvind Isaksen Microsoft Dot NET 1 18th May 2007 10:24 AM
collection object not showing properties of stored object? =?Utf-8?B?UmljaA==?= Microsoft VB .NET 5 8th Nov 2006 05:51 PM
To store object and access by key(string), what collection object is the best performance one? Thanks. david Microsoft C# .NET 1 12th Dec 2003 03:53 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:31 PM.