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
  1. Home
  2. General Programming
  3. C#
  4. Enumerate a Listbox

Enumerate a Listbox

Scheduled Pinned Locked Moved C#
visual-studiohelpquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    bxlorenz
    wrote on last edited by
    #1

    I want to Iterate thru a listBox and write the strings to a file. I have the following code that worked in VS 2005 but does not compile in VS 2008 StreamWriter f = new StreamWriter(fn); IEnumerator eEnum = this.mylistBox.Items.GetEnumerator(); if (eEnum != null) while (eEnum.MoveNext()) f.WriteLine((String) eEnum.Current); f.Close(); In VS 2008 I get a compile error saying Using the generic type 'System.Collections.Generic.IEnumerator' requires '1' type arguments Can someone explain ?

    L 1 Reply Last reply
    0
    • B bxlorenz

      I want to Iterate thru a listBox and write the strings to a file. I have the following code that worked in VS 2005 but does not compile in VS 2008 StreamWriter f = new StreamWriter(fn); IEnumerator eEnum = this.mylistBox.Items.GetEnumerator(); if (eEnum != null) while (eEnum.MoveNext()) f.WriteLine((String) eEnum.Current); f.Close(); In VS 2008 I get a compile error saying Using the generic type 'System.Collections.Generic.IEnumerator' requires '1' type arguments Can someone explain ?

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      Hi, Since .NET 2.0 some interfaces such as IEnumerator exist in non-generic and generic form; if you have a "using System.Collections.Generic" statement and no "using System.Collections", then the compiker will insist you use IEnumerator<someType>. If you want to know more, I suggest you read up on "generics". BTW: you could avoid all this by using a foreach statement, e.g. foreach(object item in myListBox.Items) and then probably work with item.ToString(). :)

      Luc Pattyn


      Have a look at my entry for the lean-and-mean competition; please provide comments, feedback, discussion, and don’t forget to vote for it! Thank you.


      Local announcement (Antwerp region): Lange Wapper? Neen!


      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

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