C traverses all elements of an enumerated type
- 2020-05-10 18:39:28
- OfStack
For example, an enumeration type with an error is defined
public enum eErrorDetailCode : int
{
Log in successfully = 0,
logout = 1,
Application error = 2,
successful = 16,
failure = 17
}
Need to quote
using System;
then loops through all the elements of the enumeration object
foreach (int myCode in Enum.GetValues(typeof(eErrorDetailCode)))
{
string strName =Enum.GetName(typeof(eErrorDetailCode), myCode);// Get the name
string strVaule = myCode.ToString();// Get the value
ListItem myLi = new ListItem(strName,strVaule);
ddlType.Items.Add(myLi);// Added to the DropDownList controls
}