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();
         }
     }
}

image

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();
         }
     }
}

image

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 me1237guy 的頭像
    me1237guy

    天天向上

    me1237guy 發表在 痞客邦 留言(0) 人氣()