Has anyone had to assign a list to an ISet? How do I go about and do this?
Say I have the class
class Foo
{
ISet<Item> Items { get; set; }
}
Now, I want to do the following:
var foo = new Foo() { Items = new List<Item>() { new Item() } }
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Keep in mind that a
Set, unlike aList, must contain every element exactly once. Therefore, ifmyListcontains multiple copies of some elements, all those copies, except one, will not make it into the set.Equality of elements (for detecting multiple copies) is defined by the
EqualsandGetHashCodemethods. If you would like to use a different definition of equality, you can use the overload ofHashSetconstructor that takes anIEqualityComparer<Item>.