using System;
namespace ConsoleAppTest
{
// 定义枚举类型
enum orientation : byte
{
north = 1,
sourth = 2,
east = 3,
west = 4
}
struct rout
{
public orientation direction;
public double distance;
}
class Program
{
static void Main(string[] args)
{
byte directionByte;
string diretcionString;
rout myRoute;
// 引用枚举类型
orientation myDirection = orientation.north;
Console.WriteLine($"myDirection = {myDirection}");
directionByte = (byte)myDirection;
diretcionString = Convert.ToString(myDirection);
Console.WriteLine($"byte equivalent = {directionByte}");
Console.WriteLine($"string equivalent = {diretcionString}");
myRoute.direction = orientation.north;
myRoute.distance = 100.1;
Console.WriteLine($"路径的方向是{myRoute.direction}");
Console.WriteLine($"路径的距离是{myRoute.distance}");
Console.ReadKey();
}
}
}
C#枚举和结构变量类型
最新推荐文章于 2024-09-10 21:41:16 发布