Материал из .Net Framework эксперт
(разн.) ← Предыдущая | Текущая версия (разн.) | Следующая → (разн.)
Comparing Enumeration Values with CompareTo()
using System;
public class MainClass
{
public enum Color
{
Red = 0,
Orange,
Yellow,
Green,
Blue,
Indigo,
Violet
}
static void Main()
{
Color MyColor;
MyColor = Color.Green;
Console.WriteLine("{0}", MyColor.rupareTo(Color.Red));
Console.WriteLine("{0}", MyColor.rupareTo(Color.Green));
Console.WriteLine("{0}", MyColor.rupareTo(Color.Violet));
}
}
Define Enums
enum Colors
{
red,
green,
blue
}
Retrieving an Enumeration Name with GetName()
using System;
public enum LegalDoorStates
{
DoorStateOpen,
DoorStateClosed
}
class DoorController
{
private LegalDoorStates CurrentState;
public LegalDoorStates State
{
get
{
return CurrentState;
}
set
{
CurrentState = value;
}
}
}
class MainClass
{
public static void Main()
{
DoorController Door;
string EnumName;
Door = new DoorController();
Door.State = LegalDoorStates.DoorStateOpen;
EnumName = LegalDoorStates.GetName(typeof(LegalDoorStates), Door.State);
Console.WriteLine(EnumName);
}
}
Using the LegalDoorStates Enumeration
public enum LegalDoorStates
{
DoorStateOpen,
DoorStateClosed
}
class DoorController
{
private LegalDoorStates CurrentState;
public LegalDoorStates State
{
get
{
return CurrentState;
}
set
{
CurrentState = value;
}
}
}
class MainClass
{
public static void Main()
{
DoorController Door;
Door = new DoorController();
Door.State = LegalDoorStates.DoorStateOpen;
}
}