using
System;
using System.Collections.Generic;
using System.Text;
namespace enumtrasform
... {
enum Range : long ...{ Max = 2147483648L, Min = 255L };
class Program
...{
static void Main(string[] args)
...{
long x = (long)Range.Max;
long y = (long)Range.Min;
Console.WriteLine("Max = {0}", x);
Console.WriteLine("Min = {0}", y);
}
}
}
using System.Collections.Generic;
using System.Text;
namespace enumtrasform
... {
enum Range : long ...{ Max = 2147483648L, Min = 255L };
class Program
...{
static void Main(string[] args)
...{
long x = (long)Range.Max;
long y = (long)Range.Min;
Console.WriteLine("Max = {0}", x);
Console.WriteLine("Min = {0}", y);
}
}
}
using
System;
using System.Collections.Generic;
using System.Text;
namespace Flags
... {
class Program
...{
enum SingleHue : short
...{
Black = 0,
Red = 1,
Green = 2,
Blue = 4
};
// Define an Enum with FlagsAttribute.
[FlagsAttribute]
enum MultiHue : short
...{
Black = 0,
Red = 1,
Green = 2,
Blue = 4
};
static void Main(string[] args)
...{
Console.WriteLine("FlagsAttribute的例子 ");
Console.WriteLine("首先是没有FlagsAttribute的例子");
// 没有FlagsAttribute.
for (int val = 0; val <= 8; val++)
Console.WriteLine("{0,3} - {1}",val, ((SingleHue)val).ToString());
Console.WriteLine(" 有FlagsAttribute: ");
// 有FlagsAttribute
for (int val = 0; val <= 8; val++)
Console.WriteLine("{0,3} - {1}",val, ((MultiHue)val).ToString());
}
}
}
using System.Collections.Generic;
using System.Text;
namespace Flags
... {
class Program
...{
enum SingleHue : short
...{
Black = 0,
Red = 1,
Green = 2,
Blue = 4
};
// Define an Enum with FlagsAttribute.
[FlagsAttribute]
enum MultiHue : short
...{
Black = 0,
Red = 1,
Green = 2,
Blue = 4
};
static void Main(string[] args)
...{
Console.WriteLine("FlagsAttribute的例子 ");
Console.WriteLine("首先是没有FlagsAttribute的例子");
// 没有FlagsAttribute.
for (int val = 0; val <= 8; val++)
Console.WriteLine("{0,3} - {1}",val, ((SingleHue)val).ToString());
Console.WriteLine(" 有FlagsAttribute: ");
// 有FlagsAttribute
for (int val = 0; val <= 8; val++)
Console.WriteLine("{0,3} - {1}",val, ((MultiHue)val).ToString());
}
}
}
结果为:
FlagsAttribute的例子
首先是没有FlagsAttribute的例子
0 - Black
1 - Red
2 - Green
3 - 3
4 - Blue
5 - 5
6 - 6
7 - 7
8 - 8
有FlagsAttribute:
0 - Black
1 - Red
2 - Green
3 - Red, Green
4 - Blue
5 - Red, Blue
6 - Green, Blue
7 - Red, Green, Blue
8 - 8