zoukankan      html  css  js  c++  java
  • Part 45 to 47 Talking about Enums in C#

    Part 45   C# Tutorial   Why Enums

    Enums are strongly typed constants.

    If a program uses set of integral numbers, consider replacing them with enums. Otherwise the pragram becomes less 

    Readable Maintainable

    Part 46   C# Tutorial   Enums Example

    public enum gender
    {
         male,
         female
    }

    Part 47   C# Tutorial   Enums in c#

    If a program uses set of intergral numbers, consider replacing them with enums,which makes the program more readable and maintainable

    1,Enums are enumerations.

    2,Enums are strongly typed constants(常量). Hence(因此),an explicit(显式) cast is needed to convert from enum type to an integral type and vice versa.Also, an enum of one tpe cannot be implicitly(隐式)  assigned(指定) to an enum of another type even though the underlying value of their members are the same.

    3,the default underlying type of an enum is int.

    4, the defalut value for first element is ZERO and gets incremented(递增) by 1.

    5,It is possible to customize the underlying type and values.

    6,Enums are value types.

    7,Enum keyword(all small letteres) is used to create enumerations, where as Enum class,contains static GetValues() and Get Names() methods which can be used to list Enum underlying type values and Names.

  • 相关阅读:
    利用ssh的私钥登录Linux server
    PSR-2 代码风格规范
    MySQL的四种事务隔离级别
    table添加横向滚动条
    转换图片大小
    百度地图Label 样式:label.setStyle
    鼠标的几种常用样式
    百度地图API-自定义图标覆盖物
    微信公众号自定义菜单中可加入的表情
    微信公众号项目总结
  • 原文地址:https://www.cnblogs.com/gester/p/4227589.html
Copyright © 2011-2022 走看看