C#语言入门详解(刘铁锰)---泛型

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,

     }

}


请使用浏览器的分享功能分享到微信等