using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleEnum
{
class EnumTest
{
enum MyColor
{
Red,
Blue,
Green
}
static void Main(string[] args)
{
Console.WriteLine("紅色: " + MyColor.Red);
Console.WriteLine("綠色: " + MyColor.Green);
Console.WriteLine("藍色: " + MyColor.Blue);
Console.WriteLine("紅色: " + (int)MyColor.Red);
Console.WriteLine("綠色: " + (int)MyColor.Green);
Console.WriteLine("藍色: " + (int)MyColor.Blue);
Console.ReadLine();
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleEnum
{
class EnumTest
{
enum MyColor
{
Red,
Blue,
Green
}
struct Product
{
public string No, Name;
public int Price;
public MyColor Color;
}
static void printCPU(ref Product cpu)
{
Console.WriteLine("產品編號: " + cpu.No);
Console.WriteLine("產品名稱: " + cpu.Name);
Console.WriteLine("產品單價: " + cpu.Price);
Console.WriteLine("產品顏色: " + cpu.Color);
}
static void Main(string[] args)
{
Console.WriteLine("紅色: " + MyColor.Red);
Console.WriteLine("綠色: " + MyColor.Green);
Console.WriteLine("藍色: " + MyColor.Blue);
Console.WriteLine("紅色: " + (int)MyColor.Red);
Console.WriteLine("綠色: " + (int)MyColor.Green);
Console.WriteLine("藍色: " + (int)MyColor.Blue);
//==============================================
Product cpu;
cpu.No = "PC01";
cpu.Name = "Win7 Home";
cpu.Price = 9900;
cpu.Color = MyColor.Red;
printCPU(ref cpu);
Console.ReadLine();
}
}
}
留言列表