Click here to Skip to main content
15,298,794 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have an object collection of month and year.

How can I take unique month and year of that object collection?
Posted
Updated 18-Oct-10 1:15am
v2
Comments
Dalek Dave 18-Oct-10 7:15am
   
Edited for Grammar.

Depends on the task at hand.

Are you wanting to select from a listbox?

Match a previously supplied option?

More information regarding what you have done and what the context is please.
   
You can try it this way, but I'm not entirely sure what the outcome will be since you're evidently comparing two separate properties withiong the object in the collection.

C#
var list = (from item in collection
            select item.).Distinct();


Of course, you can always implement a comparare class to pass to the Distinct() method that will handle the comparison in a more specific anner.

C#
public class MyObjectComparer : IEqualityComparer<myobject>
{
    public bool Equals(MyObject x, MyObject y)
    {
        bool equals = false;
        if (x != null && y != null)
        {
            equals = (x.Month == y.Month && x.Day == y.Day);
        }
        return equals;
    }
}

   ...
   MyObjectComparer comparer = new MyObjectComparer();
   var list = (from item in collection
               select item.).Distinct(comparer);


The code above is in C# but you shouldn't have any problems converting it to VB.
   
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900