Can't Figure Out How To Implement IEnumerable T

I have no problem implementing IEnumerable but can't figure out how to implement IEnumerable<T>. Using the non-generic ArrayList, I have this code:
class PeopleCollection : IEnumerable
ArrayList people = new ArrayList();
public PeopleCollection() { }
public IEnumerator GetEnumerator()
return people.GetEnumerator();
class Program
static void Main(string[] args)
PeopleCollection collection = new PeopleCollection();
foreach (Person p in collection)
Console.WriteLine(p);
I'm trying to do the same thing (using a List<Person> as the member variable instead of ArrayList) but get compile errors involving improper return types on my GetEnumerator() method. I start out with this:
class PeopleCollection : IEnumerable<Person>
List<Person> myPeople = new List<Person>();
public PeopleCollection() { }
public IEnumerator<Person> GetEnumerator()
throw new NotImplementedException();
IEnumerator IEnumerable.GetEnumerator()
throw new NotImplementedException();
class Program
static void Main(string[] args)
// Create a PeopleCollection object.
PeopleCollection peopleCollection = new PeopleCollection();
// Iterate over the collection.
foreach (Person p in peopleCollection)
Console.WriteLine(p);
Console.ReadLine();
That code compiles (basically because I haven't really done anything yet), but I get compile errors when I try to implement the GetEnumerator() methods.

The List<T> class implements the IEnumerable<T> interface, so your enumerator can return the GetEnumerator call from the list.
class PeopleCollection : IEnumerable<Person>
List<Person> myPeople = new List<Person>();
public PeopleCollection() { }
public IEnumerator<Person> GetEnumerator()
return myPeople.GetEnumerator();
IEnumerator IEnumerable.GetEnumerator()
return myPeople.GetEnumerator();
class Program
static void Main(string[] args)
// Create a PeopleCollection object.
PeopleCollection peopleCollection = new PeopleCollection();
// Iterate over the collection.
foreach (Person p in peopleCollection)
Console.WriteLine(p);
Console.ReadLine();

Similar Messages

  • Can't figure out how to use home sharing

    Since the latest couple iTunes updates, my family and I can not figure out how to use home sharing. Everyone in our household has their own iTunes, and for a long time we would just share our music through home sharing. But with the updates, so much has changed that we can no longer figure out how to use it.
    I have a lot of purchased albums on another laptop in the house, that im trying to move it all over to my own iTunes, and I have spent a long time searching the internet, and everything. And I just can't figure out how to do it. So.... how does it work now? I would really like to get these albums from my moms iTunes, onto mine. I would hate to have to buy them all over again.
    If anyone is able to help me out here, that would be great! Thanks!

    The problem im having is that after I am in another library through home sharing, I can't figure out how to select an album and import it to my library. They used to have it set up so that you just highlight all of the songs you want, and then all you had to do was click import. Now I don't even see an import button, or anything else like it. So im lost... I don't know if it's something im doing wrong, or if our home sharing system just isn't working properly.
    Thanks for the help.

  • Something was hidden in a download and now these double green underlined hyperlinks show up everywhere, and pop ups too whenever I click on ANYTHING. I can't figure out how to find it and get rid of it.

    Something was hidden in a download and now these double green underlined hyperlinks show up everywhere, and pop ups too whenever I click on ANYTHING. I can't figure out how to find it and get rid of it.

    You installed the "DownLite" trojan, perhaps under a different name. Remove it as follows.
    Malware is constantly changing to get around the defenses against it. The instructions in this comment are valid as of now, as far as I know. They won't necessarily be valid in the future. Anyone finding this comment a few days or more after it was posted should look for more recent discussions or start a new one.
    Back up all data.
    Triple-click anywhere in the line below on this page to select it:
    /Library/LaunchAgents/com.vsearch.agent.plist
    Right-click or control-click the line and select
    Services ▹ Reveal in Finder (or just Reveal)
    from the contextual menu.* A folder should open with an item named "VSearch" selected. Drag the selected item to the Trash. You may be prompted for your administrator login password.
    Repeat with each of these lines:
    /Library/LaunchDaemons/com.vsearch.daemon.plist
    /Library/LaunchDaemons/com.vsearch.helper.plist
    /Library/LaunchDaemons/Jack.plist
    Restart the computer and empty the Trash. Then delete the following items in the same way:
    /Library/Application Support/VSearch
    /Library/PrivilegedHelperTools/Jack
    /System/Library/Frameworks/VSearch.framework
    Some of these items may be absent, in which case you'll get a message that the file can't be found. Skip that item and go on to the next one.
    From the Safari menu bar, select
    Safari ▹ Preferences... ▹ Extensions
    Uninstall any extensions you don't know you need, including any that have the word "Spigot" in the description. If in doubt, uninstall all extensions. Do the equivalent for the Firefox and Chrome browsers, if you use either of those.
    This trojan is distributed on illegal websites that traffic in pirated movies. If you, or anyone else who uses the computer, visit such sites and follow prompts to install software, you can expect much worse to happen in the future.
    You may be wondering why you didn't get a warning from Gatekeeper about installing software from an unknown developer, as you should have. The reason is that the DownLite developer has a codesigning certificate issued by Apple, which causes Gatekeeper to give the installer a pass. Apple could revoke the certificate, but as of this writing, has not done so, even though it's aware of the problem. This failure of oversight is inexcusable and has compromised the value of Gatekeeper and the Developer ID program. You can't rely on Gatekeeper alone to protect you from harmful software.
    *If you don't see the contextual menu item, copy the selected text to the Clipboard by pressing the key combination  command-C. In the Finder, select
    Go ▹ Go to Folder...
    from the menu bar and paste into the box that opens by pressing command-V. You won't see what you pasted because a line break is included. Press return.

  • If I open a photo in "preview", multiple photos open. I just want to open one, but can't figure out how to do it.

    I keep multiple photos in a desktop folder to be quickly accessed by using Preview. But when I try to open ONE photo, it opens multiple photos. Can't figure out how to display just the single one that I select.  OS 10.7.2

    This is the resume feature of Lion. The last state of the application is saved when quitting (i.e last pictures viewed in Preview, last videos viewed in Quicktime etc).
    You can switch it off for Preview by copy and pasting the following in to the terminal application
    defaults write com.apple.Preview NSQuitAlwaysKeepsWindows -bool false

  • How do I use my iPhone to connect to the Internet. I down loaded safari v5.1.7 for my PC. I have added my iPhone to my computer but I can't figure out how to setup a hotspot or configure a network so my PC can access my phones data plan. Please help.

    And how am I supposed to answer my own question?

    I can't figure out how to respond so ill go this route. I can't seem to find the button/place to which I can choose, to turn on a hot spot. I have been through every option and searched to no avail. Could it be that my iPhone 4 is not hotspot capable as I was led to believe by the apple sales associate? Is there an app I can find to make my phone a wifi hotspot? So I can get on the Internet to view the pages I want that require adobe which this piece of **** software monger won't even support?

  • How do I use GarageBand as a amp/speaker to listen to my Electronic Drum set? I have a MIDI-USB cord already but I can't figure out how to listen to my set through the software using my computer speakers?

    How do I use GarageBand as a amp/speaker to listen to my Electronic Drum set? I have a MIDI-USB cord already but I can't figure out how to listen to my set through the software using my computer speakers?

    If you want to listen to the sounds of your drum set, you should use an audio cable and connect it to the computer's line-in, then create a real instrument track.
    If you use a Midi/USB interface, you'll have to create a software instrument track and select one of GB's drumsets as the instrument. Hopefully your drumset's midi notes are mapped to the right sounds in GB.

  • I gifted a ringtone to my sister that I purchased from the iTunes store, and it is on her phone, but we can't figure out how to get it moved to her ringtones.  Can anyone help?

    I gifted a ringtone to my sister that I purchased from the iTunes store, and it is on her phone, but we can't figure out how to get it moved to her ringtones.  Can anyone help?

    Edit > Preferences.  Select the check box for Ringtones, this will add them to the listing in iTunes. 
    Not sure that really answers your question though.

  • I am having trouble setting up icloud it keeps sending me back to install instructions and I'm just getting frustrated. So far I'm not liking the new itunes I can't figure out how to  look at my duplicate music like I used to.

    I can't sign on to icloud. It says I need an icloud account. I click the help option it send me back to the same page. I reinstall it nothing.
    Download the iCloud Control Panel.
    To enable iCloud on your Windows PC, first set up iCloud on your other devices, then install the iCloud Control Panel for Windows (Windows Vista with Service Pack 2 or Windows 7 required).
    ok I can't seem to set up iCloud on any device I don't understand... Ive already installed it three times.
    Turn on iCloud.
    From the Windows Start menu, choose iCloud Control Panel.
    Enter the Apple ID you used to create your iCloud account and select the iCloud services you’d like to enable.
    For mail, contacts, and calendars, you can use iCloud.com or Outlook 2007 or later.
    there is no iCloud control panel but I click on i cloud. Then entere the Apple ID you used to create your iCloud account - WHAT!!!!? where is this I keep trying to find out how to create and iCloud account but I keep getting these stupid directions!!!
    Enable automatic downloads.
    To enable automatic downloads for your music, apps, and books, open iTunes > Edit > Preferences > Store and select Music, Apps, and Books.* (Requires iTunes 10.5 or later.)
    - This is the only step that makes sense and already did it...
    Turn on iCloud for the rest of your devices.
    To get the most out of iCloud, set it up everywhere.
    This is soooo frustrating!!!!
    Also I want to be able to look at duplicate songs on my itunes but after I downloaded the new version I can not figure out how to get that back. If the duplicate setting isn't in the new itunes I want the old version back.

    Did you ever resolve the iCloud problem.I am in the same position and its driving me mad!!! If you have a link to an solution I would appreciate it.

  • I can't figure out how to import my native instruments into the library

    I'm trying to use Komplete 8 as a plug-in and I can't figure out how to put it in to library.

    Load the plugin into the insert, select your patch and then select "save as" from the channel strip menu.

  • I can't figure out how to sync my songs I downloaded to my itunes?

    I downloaded songs to itunes on my computer.  I can't figure out how to sync them to my ipod.  It says to click devices and pull up my ipod, but there is no "devices" listed, though I have registered, etc.?

    Connect your iPod to the computer with the provided cable.
    Open up iTunes.
    You should see your iPod in the Device list.
    Click on it.
    Choose what you want to sync to your iPod and then click Sync.

  • I can't figure out how to get my music to shuffle on my iPhone 5s. If I try to skip a song, it skips about 100 songs. It only ends up playing 4 or 5 songs then goes back to the song menu. Help please!

    I can't figure out how to get the music on my iPhone5s to shuffle. If I use the arrows to skip a song, it shuffles through a handful of the same songs then goes back to the song menu. Help please!

    Un-sync all your music to remove it from the device, then restart (hold down the home button along with the sleep/wake button until you see the apple, then let go). Now re-sync your music.

  • I can't figure out how to resize my picture for my home or lock screens.

    I can't figure out how to resize my picture for my home or lock screens. It shouldn't be his difficult. Any suggestions? I'm running the latest software. Thanks.

    whichever app store you are connecting to, hyou need a credit card with an address in that country. Also, itunes gift cards must be in local currency too.
    If you are in japan, you need to use the japan app store

  • I can't figure out how to transfer my albums on my iphone to photo stream so that I can see them on my apple computer. It did not automatically sync.

    I can't figure out how to transfer my albums on my iphone to photo stream so that I can see them on my apple computer. It did not automatically sync.

    kellyfromdanville wrote:
    I am new to Apple!
    Ah, new to routers too.
    Perhaps it's best to have a local computer support person come set you up?
    To explain everything would require writing a book here.
    But this is what you want basically.
    Router, new Wireless N, firmware updated.
    1: Two accounts, one admin, one guest Internet access. Random +30 plus character lenght passwords each preferred.
    (guest password to max password length of any iDevices)
    2: Encryption: WPA2 AES. No Ping. No remote access. No MAC filtering. Visible.
    3: Guest access on devices and computers only.  Passwords written down and stored.
    4: OpenDNS preferred but not mandatory.
    If you get OpenDNS, you can log into their website for free and set parental controls on things like inappropriate sites for children. So whatever device is used on your network can't access a large portion of those sites (nothing is perfect) by most users who are not technical oriented.
    What your doing now is running the bare bones unsecure router which can be used harmfully against you.
    Even a Apple Airport router has to be very well secured. The defautl cd and out of the box setup is not a secure solution.

  • I am trying to connect my new iMac to my Buffalo router.  I forgot my router password, so I reset it and it is working.  I can't figure out how to reset my router password and lock it on my iMac.

    I am connecting my new iMac to my Buffalo router.  I forgot my router password so I pushed the reset button and my computer was able to connect.  The problem is, I can't figure out how to set my new password and lock the router.  I went to the Buffalo website and downloaded the CD, as I can't find that either.  I can't open any of it because it says it is Windows and can't open it.  I am new to Apple!

    kellyfromdanville wrote:
    I am new to Apple!
    Ah, new to routers too.
    Perhaps it's best to have a local computer support person come set you up?
    To explain everything would require writing a book here.
    But this is what you want basically.
    Router, new Wireless N, firmware updated.
    1: Two accounts, one admin, one guest Internet access. Random +30 plus character lenght passwords each preferred.
    (guest password to max password length of any iDevices)
    2: Encryption: WPA2 AES. No Ping. No remote access. No MAC filtering. Visible.
    3: Guest access on devices and computers only.  Passwords written down and stored.
    4: OpenDNS preferred but not mandatory.
    If you get OpenDNS, you can log into their website for free and set parental controls on things like inappropriate sites for children. So whatever device is used on your network can't access a large portion of those sites (nothing is perfect) by most users who are not technical oriented.
    What your doing now is running the bare bones unsecure router which can be used harmfully against you.
    Even a Apple Airport router has to be very well secured. The defautl cd and out of the box setup is not a secure solution.

  • I'm trying to connect a BlueTooth headset to my Mac Mini. I can discover it, but soon after discovery it disconnects. Can't figure out how to reconnect. My only option seems to be re-discovery

    I can discover the headset, but soon after discovery it disconnects. Haven't been able to figure out how to try to re-connect. And the help section titled "Use BlueTooth has absolutely no information on how to use it. All I can do is re-discover it. Every time I rediscover it, it disconnects shortly afterward. This headset works well with both my iPhone and iPad and has for quite some time. But it won't stay connected to my Mac.

    Tried with another headset that works fine with iPhone and iPad. An LG HBS700. Same problem. It connects for maybe 10 seconds and then disconnects. So it must be a problem on the Mac. But this Mini is out of warrentee so taking it into an Apple store to get it repaired isn't a good solution. Maybe as a last resort.
    Is there a way to select connect on the Mac? Everything else I've connected a BlueTooth device to has both a command for pairing and a command for connecting or reconnecting. I can't figure out how to select connect on the Mac.

Maybe you are looking for

  • Creation of Billing Document

    Hi Experts,      while creating Billing Doc in Logistics with deliveryNo as reference i am getting error that no accounting document generated. can u suggest me why this occured     thanks in advance

  • Issue with Auto PO creation

    Hello Gurus, Kindly help me with this issue. I have user who is using ME59 for the auto PO creation.When he runs this transaction with the "TEST RUN" flaged,in the result screen he is able to see a mesasage as "PO creation successfull" along with the

  • My preview site displays correctly but my live site changes when I publish it

    My issue is that the preview site displays correctly however when I upload this information to the live site, the format changes and displays incorrectly.

  • "Y" Adapter Recomendation?

    Can somebody recommend a good "Y" Adapter for outputting from "one" side of a video card into two monitors? I want to do this so I can output the other side to an HD External Monitor. I have found a few but they all have mixed reviews. Thanks in adva

  • Printing monthly CC invoices

    good morning. for accounting purposes I want to print my monthly invoices, but this isn't working: not for the current month, nor for historic months. does anyone else have the same problem?