tags:

views:

206

answers:

2

I know this is a very basic question, but forgive me if I did something wrong.

I have a Many-to-Many relationship using <set>. When I'm debugging the code I can see the data in the "set", but I'm not sure how to display the data.

For example I could use "foreach" for List, but I cannot use foreach with the "ISet".

In My class:

    private ISet newsList = new HashedSet();

    public ISet NewsList
    {
        get { return newsList; }
        set { newsList = value; }
    }

    public void AddNews(News item)
    {
        NewssList.Add(item);
    }

Can any provide some code sample how I can deal with this.

Many thanks.

Daoming

A: 

You can use foreach with ISet because it extends IEnumerable.

David M
I got this error: When I try to use foreach"foreach statement cannot operate on variables of type 'Iesi.Collections.ISet' because 'Iesi.Collections.ISet' does not contain a public definition for 'GetEnumerator'"
Daoming Yang
@DotNet User: check your Iesi references. ISet **does** implement ICollection (and therefore IEnumerable): https://nhibernate.svn.sourceforge.net/svnroot/nhibernate/trunk/nhibernate/src/Iesi.Collections/ISet.cs and its implementation **does** have a GetEnumerator(): https://nhibernate.svn.sourceforge.net/svnroot/nhibernate/trunk/nhibernate/src/Iesi.Collections/DictionarySet.cs
Mauricio Scheffer
+1  A: 

For example I could use "foreach" for List, but I cannot use foreach with the "ISet"

Why not? I'm gonna guess that you just need to add a reference to the Iesi.Collections.dll assembly.

HTH,
Kent

Kent Boogaart
I got this error: When I try to use foreach "foreach statement cannot operate on variables of type 'Iesi.Collections.ISet' because 'Iesi.Collections.ISet' does not contain a public definition for 'GetEnumerator'"
Daoming Yang
Yep, sounds like you need to add a reference. The error message is a little misleading.
Kent Boogaart
Thanks very much.
Daoming Yang