Imports System
Public Class EnumTest
Enum Days
Saturday
Sunday
Monday
Tuesday
Wednesday
Thursday
Friday
End Enum 'Days
Enum BoilingPoints
Celcius = 100
Fahrenheit = 212
End Enum 'BoilingPoints
<FlagsAttribute()> _
Enum Colors
Red = 1
Green = 2
Blue = 4
Yellow = 8
End Enum 'Colors
Public Shared Sub Main()
Dim weekdays As Type = GetType(Days)
Dim boiling As Type = GetType(BoilingPoints)
Console.WriteLine("The days of the week, and their corresponding values in the Days Enum are:")
Dim s As String
For Each s In [Enum].GetNames(weekdays)
Console.WriteLine("{0,-11} = {1}", s, [Enum].Format(weekdays, [Enum].Parse(weekdays, s), "d"))
Next s
Console.WriteLine()
Console.WriteLine("Enums can also be created which have values that represent some meaningful amount.")
Console.WriteLine("The BoilingPoints Enum defines the following items, and corresponding values:")
For Each s In [Enum].GetNames(boiling)
Console.WriteLine("{0,-11} = {1}", s, [Enum].Format(boiling, [Enum].Parse(boiling, s), "d"))
Next s
Dim myColors As Colors = Colors.Red Or Colors.Blue Or Colors.Yellow
Console.WriteLine()
Console.WriteLine("myColors holds a combination of colors. Namely: {0}", myColors)
End Sub 'Main
End Class 'EnumTest
using System;
public class EnumTest {
enum Days { Saturday, Sunday, Monday, Tuesday, Wednesday, Thursday, Friday };
enum BoilingPoints { Celcius = 100, Fahrenheit = 212 };
[FlagsAttribute]
enum Colors { Red = 1, Green = 2, Blue = 4, Yellow = 8 };
public static void Main() {
Type weekdays = typeof(Days);
Type boiling = typeof(BoilingPoints);
Console.WriteLine("The days of the week, and their corresponding values in the Days Enum are:");
foreach ( string s in Enum.GetNames(weekdays) )
Console.WriteLine( "{0,-11}= {1}", s, Enum.Format( weekdays, Enum.Parse(weekdays, s), "d"));
Console.WriteLine();
Console.WriteLine("Enums can also be created which have values that represent some meaningful amount.");
Console.WriteLine("The BoilingPoints Enum defines the following items, and corresponding values:");
foreach ( string s in Enum.GetNames(boiling) )
Console.WriteLine( "{0,-11}= {1}", s, Enum.Format(boiling, Enum.Parse(boiling, s), "d"));
Colors myColors = Colors.Red | Colors.Blue | Colors.Yellow;
Console.WriteLine();
Console.WriteLine("myColors holds a combination of colors. Namely: {0}", myColors);
}
}
using namespace System;
enum class Days
{
Saturday, Sunday, Monday, Tuesday, Wednesday, Thursday, Friday
};
enum class BoilingPoints
{
Celcius = 100,
Fahrenheit = 212
};
[FlagsAttribute]
enum class Colors
{
Red = 1,
Green = 2,
Blue = 4,
Yellow = 8
};
int main()
{
Type^ weekdays = Days::typeid;
Type^ boiling = BoilingPoints::typeid;
Console::WriteLine( "The days of the week, and their corresponding values in the Days Enum are:" );
Array^ a = Enum::GetNames( weekdays );
Int32 i = 0;
do
{
Object^ o = a->GetValue( i );
Console::WriteLine( "{0,-11}= {1}", o->ToString(), Enum::Format( weekdays, Enum::Parse( weekdays, o->ToString() ), "d" ) );
}
while ( ++i < a->Length );
Console::WriteLine();
Console::WriteLine( "Enums can also be created which have values that represent some meaningful amount." );
Console::WriteLine( "The BoilingPoints Enum defines the following items, and corresponding values:" );
i = 0;
Array^ b = Enum::GetNames( boiling );
do
{
Object^ o = b->GetValue( i );
Console::WriteLine( "{0,-11}= {1}", o->ToString(), Enum::Format( boiling, Enum::Parse( boiling, o->ToString() ), "d" ) );
}
while ( ++i < b->Length );
Array^ c = Enum::GetNames( Colors::typeid );
Colors myColors = Colors::Red | Colors::Blue | Colors::Yellow;
Console::WriteLine();
Console::Write( "myColors holds a combination of colors. Namely:" );
for ( i = 0; i < 3; i++ )
Console::Write( " {0}", c->GetValue( i ) );
}
import System.*;
public class EnumTest
{
enum Days
{
saturday (0),
sunday (1),
monday (2),
tuesday (3),
wednesday (4),
thursday (5),
friday (6);
} //Days
enum BoilingPoints
{
celsius (100),
fahrenheit (212);
} //BoilingPoints
/** @attribute FlagsAttribute()
*/
enum Colors
{
red (1),
green (2),
blue (4),
yellow (8);
} //Colors
public static void main(String[] args)
{
Type weekdays = Days.class.ToType();
Type boiling = BoilingPoints.class.ToType();
Console.WriteLine("The days of the week, and their corresponding"
+ " values in the Days Enum are:");
String s[] = Enum.GetNames(weekdays);
for (int iCtr = 0; iCtr < s.length; iCtr++) {
Console.WriteLine("{0,-11}= {1}", s[iCtr],
Enum.Format(weekdays, Enum.Parse(weekdays, s[iCtr]), "d"));
}
Console.WriteLine();
Console.WriteLine("Enums can also be created which have values that"
+ " represent some meaningful amount.");
Console.WriteLine("The BoilingPoints Enum defines the following items,"
+ " and corresponding values:");
String s1[] = Enum.GetNames(boiling);
for (int iCtr = 0; iCtr < s1.length; iCtr++) {
Console.WriteLine("{0,-11}= {1}", s1[iCtr],
Enum.Format(boiling, Enum.Parse(boiling, s1[iCtr]), "d"));
}
Colors myColors = Colors.red | Colors.blue | Colors.yellow;
Console.WriteLine();
Console.WriteLine("myColors holds a combination of colors. Namely: {0}",
myColors);
} //main
} //EnumTest
import System;
public class EnumTest {
enum Days { Saturday, Sunday, Monday, Tuesday, Wednesday, Thursday, Friday };
enum BoilingPoints { Celcius = 100, Fahrenheit = 212 };
FlagsAttribute
enum Colors { Red = 1, Green = 2, Blue = 4, Yellow = 8 };
public static function Main() {
var weekdays : Type = Days;
var boiling : Type = BoilingPoints;
Console.WriteLine("The days of the week, and their corresponding values in the Days Enum are:");
for( var i : int in Enum.GetNames(weekdays) )
Console.WriteLine( "{0,-11}= {1}", Enum.GetNames(weekdays).GetValue(i),
Enum.Format( weekdays, Enum.Parse(weekdays, Enum.GetNames(weekdays).GetValue(i)), "d"));
Console.WriteLine();
Console.WriteLine("Enums can also be created which have values that represent some meaningful amount.");
Console.WriteLine("The BoilingPoints Enum defines the following items, and corresponding values:");
for ( var j : int in Enum.GetNames(boiling) )
Console.WriteLine( "{0,-11}= {1}", Enum.GetNames(boiling).GetValue(j),
Enum.Format(boiling, Enum.Parse(boiling, Enum.GetNames(boiling).GetValue(j)), "d"));
var myColors : Colors = Colors.Red | Colors.Blue | Colors.Yellow;
Console.WriteLine();
Console.WriteLine("myColors holds a combination of colors. Namely: {0}", myColors);
}
}