Skip to content

Instantly share code, notes, and snippets.

@AndrewBarfield
Created April 30, 2012 08:27
Show Gist options
  • Save AndrewBarfield/2556542 to your computer and use it in GitHub Desktop.
Save AndrewBarfield/2556542 to your computer and use it in GitHub Desktop.
C#: System.Collections.Generic: Enumerating a Generic list
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace GenericListEnumerator {
class Program {
public class Domain {
public Domain(string name) {
this.name = name;
}
private readonly string name;
public string Name {
get {
return name;
}
}
}
static void Main(string[] args) {
// Create a List of Domains
List<Domain> domains = new List<Domain>
{
new Domain(".com"),
new Domain(".net"),
new Domain(".gov"),
new Domain(".mil"),
new Domain(".edu")
};
// Get a Domain enumerator
IEnumerator<Domain> enumerator = domains.GetEnumerator();
// Iterate domains List using the domains Enumerator
while ( enumerator.MoveNext() ) {
Domain domain = enumerator.Current;
Console.WriteLine( domain.Name );
}
// Allow user to read the Console
Console.ReadLine();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment