Created
April 30, 2012 08:27
-
-
Save AndrewBarfield/2556542 to your computer and use it in GitHub Desktop.
C#: System.Collections.Generic: Enumerating a Generic list
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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