C# - implementing GetEnumerator() for a collection inherited from List<string>
Posted
by Vojtech
on Stack Overflow
See other posts from Stack Overflow
or by Vojtech
Published on 2010-03-21T06:45:36Z
Indexed on
2010/03/21
6:51 UTC
Read the original article
Hit count: 242
Hi,
I am trying to implement FilePathCollection. Its items would be simple file names (without a path - such as "image.jpg"). Once the collection is used via foreach cycle, it should return the full path created by concatenating with "baseDirectory". How can I do that?
public class FilePathCollection : List<string>
{
string baseDirectory;
public FileCollection(string baseDirectory)
{
this.baseDirectory = baseDirectory;
}
new public System.Collections.IEnumerator GetEnumerator()
{
foreach (string value in this._list) //this does not work because _list is private
yield return baseDirectory + value;
}
}
Thanks in advance! :-)
© Stack Overflow or respective owner