Jump to content
  • Advertisement
Sign in to follow this  
dAND3h

Attempting Custom Collection

This topic is 2270 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I am attempting to create a custom collection to hold some information so that I can search an index based on an enum I created.

public class MyCollection: IEnumerable<Films>,IEnumerable
{
public int Count
{
get
{
return this.Count;
}

}
public Films this[FilmName name]
{
get
{
return this[type];
}
set
{
this[type] = value;
}
}

IEnumerator<Films> IEnumerable<Films>.GetEnumerator()
{
throw new System.NotImplementedException();
}
IEnumerator IEnumerable.GetEnumerator()
{
throw new System.NotImplementedException();
}
}



FilmName is the enum.

Whenever I try to access the collection theFilms[FilmName.Stargate].Name for example, it says "Can't modify return value of MyCollection.this[FilmName] because it is not a variable"


I am also not sure if I am doing the thing right, I just auto implemented the interface methods.

Share this post


Link to post
Share on other sites
Advertisement
You are missing some of the critical code with your post. What you posted doesn't give the error.

Properties, or items with get{} and set{} interfaces, cannot be modified. You can read from them, and you can write to them, but you cannot modify them.

For example, you could no say theFilms[FilmName.Stargate].Count += 4; That sort of statement mixes get and set.

Instead, you can run both the get and set operations separately: theFilms[FilmName.Stargate].property = theFilms[FilmName.Stargate].property + 5;

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!