Re: singleton ienumerable, need to add more...

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



OK, one thing at a time.

I think the "indexer" syntax you are looking for is:

public Folder this[int rowIndex]
{
get
{
return new Folder(DT.Rows[rowIndex]);
}
}

you can then access Folders.SiteFolders[4]; (etc)

Note that I tweaked the return type to be useful. However, the bigger
points:

* it is unusual for something to be enumerable and an enumerator; I
suspect you just mean IEnumerable or IEnumerable<Folder>
* Thread safety: since you appear new to C# this probably won't be an
issue, but in general static methods should be thread safe, which
SiteFolders isn't
* could just pass up the obtained enumerator, rather than the
smoke'n'mirrors?
* each call to Current returns a different object; this could get very,
very confusing, and lead to all sorts of fun
* minor comment issue: this is merely a cast, not polymorphism
* not sure this is really suited to a singleton pattern - although that
might just be that I don't know enough about the context, so I'll give
you the benefit of the doubt

Given that you seem to have a wrapper object (Folder), there may be a
lot of benefit in moving to a List<Folder> implementation; this would
allow you to hand over a simple enumerator without all the fuss, and
your Folder objects would only exist once each- you'd just loop over
the DataTable.


Let me know if you want more help,

Marc

.



Relevant Pages

  • Re: singleton ienumerable, need to add more...
    ... I did try something similar to the public Folder thisbut kept ... At the moment, thread safety is not an issue, but is likely to be as the ... (Pass the obtoned enumerator) Can you give me some pointers? ... not sure this is really suited to a singleton pattern - although that ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: singleton ienumerable, need to add more...
    ... I did try something similar to the public Folder thisbut kept ... At the moment, thread safety is not an issue, but is likely to be as the ... (Pass the obtoned enumerator) Can you give me some pointers? ... not sure this is really suited to a singleton pattern - although that ...
    (microsoft.public.dotnet.languages.csharp)
  • This is driving me nuts!
    ... var item = args.Item; ... folder = fso.GetFolder; ... fc = new Enumerator; ... infront of it! ...
    (microsoft.public.scripting.wsh)
  • Listing file names from a folder into Excel
    ... Sub files() ... RowIndex = RowIndex + 1 ... would like to list all the files in a particular folder. ...
    (microsoft.public.excel.misc)