C#語言入門詳解(劉鐵錳)---泛型

專注的阿熊發表於2021-08-25

using System;

namespace Enum

{

     class Program

     {

         static void Main(string[] args)

         {

             Console.WriteLine("-------------test-------------");

             Person employee = new Person(0100, "996 工賊 ", ELevel.Employee);

             Person boss = new Person(0002, "2 號老闆 ", ELevel.Boss);

             Person bigboss = new Person(0001, "1 號老闆 ", 外匯跟單gendan5.comELevel.BigBoss);

             employee.Skill = ESkill.Csharp | ESkill.JavaScript | ESkill.Python;

             boss.Skill = ESkill.Teach | ESkill.Comminication;

             Console.WriteLine(employee.GetInfo());

             Console.WriteLine(boss.GetInfo());

             Console.WriteLine("-------------Done-------------");

         }

     }

     class Person

     {

         public int ID { get; set; }

         public string Name { get; set; }

         public ELevel Level { get; set; }

         public ESkill Skill { get; set; }

         public Person(int id, string name, ELevel level)

         {

             this.ID = id;

             this.Name = name;

             this.Level = level;

         }

         public string GetInfo()

         {

             string str = $"ID: {this.ID.ToString("D4")}, \r\n"

                        + $"Name: {this.Name}, \r\n"

                        + $"Level: {this.Level},\r\n"                      

                        ;

             for (int i = 0; i < 10; i++)

             {

                 ESkill temp = (ESkill)(int)Math.Pow(2, i);

                 if ( (this.Skill & temp) == temp) // 按位取與,結果為真則表示擁有這項技能

                 {

                     str += $"Skill: {temp},\r\n";

                 }

             }

             return str;

         }

     }

     enum ELevel

     {

         Employee=100,

         Manager,

         Boss,

         BigBoss,

     }

     enum ESkill

     {

         // 每個成員對應的數字為 2 n 次方, n 0 開始,依次加 1

         Csharp = 1,

         Java = 2,

         JavaScript = 4,

         Python = 8,

         CPlusPlus = 16,

         C = 32,

         Teach = 64,

         Comminication = 128,

     }

}


來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/69946337/viewspace-2788792/,如需轉載,請註明出處,否則將追究法律責任。

相關文章