Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
J

jbricker77

@jbricker77
About
Posts
5
Topics
1
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • Enumerator question
    J jbricker77

    The problem is more complex than I wrote here but I will show my solution to this problem. Here is what we had. Class Foo { protected static List<T> list; list = fill_it_up(); // fills the list public class FooIterator : IEnumerator { protected int lastVisited; public FooIterator () { lastVisited = -1; _more enumeration code...._ } The FooIterator was neede by other class to enumerate through the List<>. The inner class was not working because the List has to be static. Class Bar is an object that contains 2 other objects. Here is the change: Class Foo { protected List<Bar> list; list = fill_it_up(); // fills the list public class FooIterator { private List<Bar> list; public FooIterator (List<Bar> anotherList) { list = anotherList; } public IEnumerator<FeFiFoe> GetEnumerator() { foreach (Bar b in list) { // returning the property FeFiFoe object from the Bar object yield return b.thisFeFiFoe; } } } Hope this helps someone else.

    C# help csharp java question

  • Enumerator question
    J jbricker77

    I think I figured out why I'm having the problem but I still can not figure a way around it yet. FooIterator in an inner class so it can only acess list if list is a static attribute. So I made changes like so: public object Current { get { return Foo.list[lastVisited].thisBar; } But when checking the degugger, when I load Foo.list is is fine. When I access it via the Iterator inner class it is empty. I tried to get rid of the inner class and return the static list and that did not work. What I need to do is immitate the Java Iterator but this seems impossible because of the static attribute contrate on inner classes.

    C# help csharp java question

  • Enumerator question
    J jbricker77

    Tried this but did not work. See following post for why and a new question.

    C# help csharp java question

  • Enumerator question
    J jbricker77

    Just tried this and got an InvalidOperationException saying that the enumeration has either not started or finished.

    C# help csharp java question

  • Enumerator question
    J jbricker77

    Long time Java programmer running into a C# issue I can not figure out. I have a class that contains a List. Other classes need iterate through the list. What I have below is not working. I get an excpetion at runtime about Current being outofRange. Should I just return an Enumerator from the List or is there a way to do it like this that I'm missing. thanks for the help. Class Foo { List list; list = fill_it_up(); // fills the list public class FooIterator : IEnumerator { protected int lastVisited; public FooIterator () { lastVisited = -1; } #region IEnumerator Members public object Current { get { return list[lastVisited].thisBar; } } public bool MoveNext() { return ++lastVisited < list.Count - 1; } public void Reset() { throw new Exception("The method or operation is not implemented."); } #endregion } } }

    C# help csharp java question
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups