Using code snippet traversal, enum type enum

Source: Internet
Author: User

Some enumeration types are defined in the recent project, and you need to pass the enumerated key values to the front end for making the drop-down menu.

1, first defines the enumeration type

    Public enum int     {

Sick leave = 1,
Leave = 2,
Marriage leave = 3,
Maternity leave = 4,
Bereavement = 5

    }

Here I created a new console application that looked at the output effect,

public static void Main (string[] args)
{

foreach (var item in Enum.getvalues (typeof (absence type)))
{
Console.WriteLine (String. Format ("{0}={1}", item. ToString (), Convert.ToInt32 (item));
var mm = (leave type) Enum.parse (typeof (absence type), item. ToString ());
Console.WriteLine (mm);

}
Console.read ();
}

The effect is really what I want.

2. Then create a new object

 /// <summary>    ///type of Leave/// </summary>     Public classOffweektype {/// <summary>        ///type name/// </summary>         Public stringName {Get;Set; } /// <summary>        ///Type value/// </summary>         Public stringValue {Get;Set; } }

Assigning a value to an object

/// <summary>        ///get all the leave types/// </summary>        /// <returns></returns>         PublicResultentity<list<offweektype>>Getoffworktype () {List<OffWeekType> list =NewList<offweektype>(); foreach(varValueinchEnum.getvalues (typeof(leave type))) {                //var result = string. Format ("Name: ' {0} ', value:{1}", Value.      ToString (), Convert.ToInt32 (value)); //Traversing enumeration TypesOffweektype type =NewOffweektype {Name=value. ToString (), Value=Convert.ToInt32 (value).                ToString (),}; List.            ADD (type); }            returngetresultentity (list); }

Using code snippet traversal, enum type enum

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.