Enumerated Types with a base other than integer

I have code snippets that I have published that are scattered throughout the web. I am going to work at compiling a handfull of them here.

 

/// <summary>Indicates the forth byte of the machine’s host ip address. </summary>
///
<remarks>
///
Enum:
/// http://msdn.microsoft.com/library/default.asp?url=/library/en-us/csref/html/vcreftheenumerationtypes.asp

/// Integral Types:
///
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/csref/html/vcrefintegraltypes.asp
///
</remarks>
public enum ServerMachines : byte {
      /// <summary>The IP Address of the printer.
</summary>
      
Printer = 114,
       /// <summary>The IP Address of the database server.
</summary>
      
Database = 132,
      /// <summary>The IP Address of the web server.
</summary>
      
Web = 243,
      /// <summary>The IP Address of the firewall.
</summary>
      
Firewall = 1
};

/// <summary>Tests an enumerated type with a base-type other than the default integer. </summary>
class EnumTester {
      
private const string HOST_SUBNET_PREFIX = "192.168.0.";

      /// <summary> The main entry point for the application.</summary>
      
[STAThread]
      
static void Main(string[] args) {
            
// Iterate through the server machines
            
foreach(byte address in Enum.GetValues(typeof(ServerMachines))) {
                  
Console.WriteLine(
                        
String.Format(
                              
"The {0} server has an address of {1}{2}", 
                              
Enum.GetName(typeof(ServerMachines), address), 
                              
HOST_SUBNET_PREFIX, 
                              
address));
            
}
      
}
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s