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.

  • 相关阅读:
    使用Node.js创建第一个应用
    Node.js安装
    Node.js简介
    c#中的索引器
    ASP.NET常用内置对象(三)Server
    ASP.NET常用内置对象(二)Response
    ASP.NET常用内置对象(一)Request
    利用JDBC工具类 模拟用户登录!
    JDBC工具类完整版!
    用户登录
  • 原文地址:https://www.cnblogs.com/gester/p/4227589.html
Copyright © 2011-2022 走看看