/* C#: The Complete Reference by Herbert Schildt Publisher: Osborne/McGraw-Hill (March 8, 2002) ISBN: 0072134852 */ // Demonstrate IDictionaryEnumerator. using System; using System.Collections; public class IDicEnumDemo { public static void Main() { // Create a hash table. Hashtable ht = new Hashtable(); // Add elements to the table ht.Add("Tom", "555-3456"); ht.Add("Mary", "555-9876"); ht.Add("Todd", "555-3452"); ht.Add("Ken", "555-7756"); // Demonstrate enumerator IDictionaryEnumerator etr = ht.GetEnumerator(); Console.WriteLine("Display info using through Entry."); while(etr.MoveNext()) Console.WriteLine(etr.Entry.Key + ": " + etr.Entry.Value); Console.WriteLine(); Console.WriteLine("Display info using Key and Value directly."); etr.Reset(); while(etr.MoveNext()) Console.WriteLine(etr.Key + ": " + etr.Value); } }
ASP.NET & Csharp (C#)
ASP.NET & Csharp (C#) , Here you can find my posts about .NET c# .
Demonstrate an enumerator
/*
C#: The Complete Reference
by Herbert Schildt
Publisher: Osborne/McGraw-Hill (March 8, 2002)
ISBN: 0072134852
*/
// Demonstrate an enumerator.
using System;
using System.Collections;
public class EnumeratorDemo {
public static void Main() {
ArrayList list = new ArrayList(1);
for(int i=0; i < 10; i++) list.Add(i); // Use enumerator to access list. IEnumerator etr = list.GetEnumerator(); while(etr.MoveNext()) Console.Write(etr.Current + " "); Console.WriteLine(); // Re-enumerate the list. etr.Reset(); while(etr.MoveNext()) Console.Write(etr.Current + " "); Console.WriteLine(); } } [/csharp]
A public enum in one class from another class
/* C# Programming Tips & Techniques by Charles Wright, Kris Jamsa Publisher: Osborne/McGraw-Hill (December 28, 2001) ISBN: 0072193794 */ // // Enum.cs - Demonstrates using a public enum in one class from // another class // // Compile this program with the following command line: // C:>csc enum.cs // namespace nsEnum { using System; public class Enum { // Define the enum type public enum Weekdays { Sun, Mon, Tues, Wed, Thurs, Fri, Sat, Count } static public void Main () { clsSecond second = new clsSecond(); second.ShowEnum (); } } class clsSecond { public void ShowEnum() { // Use the class name with the enum name Console.WriteLine ("Tuesday is day {0} in the week", (int) Enum.Weekdays.Tues); } } }
how a derived class may override an existing enumeration in a base class
/* C# Programming Tips & Techniques by Charles Wright, Kris Jamsa Publisher: Osborne/McGraw-Hill (December 28, 2001) ISBN: 0072193794 */ // // BaseEnum.cs - Demonstrates how a derived class may override an existing // enumeration in a base class // // Compile this program with the following command line: // C:>csc baseenum.cs // namespace nsEnum { using System; public class clsBaseClass { // Define the enum type public enum Weekdays { Sun, Mon, Tues, Wed, Thurs, Fri, Sat } static public void Main () { Console.WriteLine ("In base class, Sunday = " + (int) Weekdays.Sun); clsNewClass second = new clsNewClass(); second.ShowEnum (); } } class clsNewClass : clsBaseClass { public new enum Weekdays { Sun = 1, Mon, Tues, Wed, Thurs, Fri, Sat } public void ShowEnum() { // Use the class name with the enum name Console.WriteLine ("In derived class, Sunday = " + (int) Weekdays.Sun); } } }
Illustrates the use of an enumeration that defines the orbital periods of the first four planets in days, using a base type of long
/* Mastering Visual C# .NET by Jason Price, Mike Gunderloy Publisher: Sybex; ISBN: 0782129110 */ /* Example2_12.cs illustrates the use of an enumeration that defines the orbital periods of the first four planets in days, using a base type of long */ public class Example2_121 { enum PlanetPeriods :long { Mercury = 88, Venus = 225, Earth = 365, Mars = 687 } public static void Main() { System.Console.WriteLine("Orbital period for Mars = " + (long) PlanetPeriods.Mars + " days"); } }
Illustrates the use of an enumeration that defines the orbital periods of the first four planets in days
/* Mastering Visual C# .NET by Jason Price, Mike Gunderloy Publisher: Sybex; ISBN: 0782129110 */ /* Example2_11.cs illustrates the use of an enumeration that defines the orbital periods of the first four planets in days */ public class Example2_111 { enum PlanetPeriods { Mercury = 88, Venus = 225, Earth = 365, Mars = 687 } public static void Main() { System.Console.WriteLine("Orbital period for Mars = " + (int) PlanetPeriods.Mars + " days"); } }
The use of an enumeration that defines the positions of the planets in the solar system relative to the Sun
/* Mastering Visual C# .NET by Jason Price, Mike Gunderloy Publisher: Sybex; ISBN: 0782129110 */ /* Example2_10.cs illustrates the use of an enumeration that defines the positions of the planets in the solar system relative to the Sun */ public class Example2_10 { enum Planets { Mercury = 1, Venus, Earth, Mars, Jupiter, Saturn, Uranus, Neptune, Pluto } public static void Main() { System.Console.WriteLine("Position of Earth = " + (int) Planets.Earth); System.Console.WriteLine("Planets.Earth = " + Planets.Earth); } }