ITPub博客

首页 > IT职业 > IT生活 > C#语言入门详解(刘铁锰)---泛型

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

IT生活 作者:专注的阿熊 时间:2021-08-25 17:27:36 0 删除 编辑

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博客 ” ,链接:https://blog.itpub.net/69946337/viewspace-2788792/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2019-08-23

  • 博文量
    410
  • 访问量
    276803