Declaration and use examples of enumeration types in C

Keywords: C# Programming

scene

There are times when enumeration types are used.

For example, if an int list is passed, the corresponding chekbox should be selected according to the list.

First, create a new class KillComponents

    public enum KillComponents
    {
        /// <summary>
        /// Upper atomizer
        /// </summary>
        ShangWuHua = 1,
        /// <summary>
        /// Lower atomizer
        /// </summary>
        XiaWuHua = 2,
        /// <summary>
        /// Upper ultraviolet lamp
        /// </summary>
        ShangZiWai = 3,
        /// <summary>
        /// Ultraviolet lamp
        /// </summary>
        XiaZiWai = 4,
        /// <summary>
        /// lifting columns
        /// </summary>
        ShengJiangZhu = 5,
        /// <summary>
        /// air cleaner
        /// </summary>
        KongQiJingHua =6
    }

 

Note:

Blog home page:
https://blog.csdn.net/badao_liumang_qizhi
Official account
Domineering procedural ape
Get programming related ebooks, tutorials and free downloads.

Realization

Then, after passing the parameters, traverse the list to each int and compare it with the enumeration type.

foreach (int index in this._killSetModel.Components)
                {
                    switch (index)
                        {
                        case (int)KillComponents.ShangWuHua :
                                this.CB_1.Checked = true;
                                break;
                        case (int)KillComponents.XiaWuHua:
                                this.CB_2.Checked = true;
                                break;
                        case (int)KillComponents.ShangZiWai:
                                this.CB_3.Checked = true;
                                break;
                        case (int)KillComponents.XiaZiWai:
                                this.CB_4.Checked = true;
                                break;
                        case (int)KillComponents.ShengJiangZhu:
                                this.CB_5.Checked = true;
                                break;
                        case (int)KillComponents.KongQiJingHua:
                                this.CB_6.Checked = true;
                                break;
                        }
                }

Posted by Ansel_Tk1 on Wed, 22 Apr 2020 07:35:39 -0700